Skip to content

perf: eliminate slow chown operations in Docker builds (~41min → seconds)#12256

Merged
raymyers merged 1 commit intoOpenHands:mainfrom
prandata:fix/chown-performance-12043
Jan 8, 2026
Merged

perf: eliminate slow chown operations in Docker builds (~41min → seconds)#12256
raymyers merged 1 commit intoOpenHands:mainfrom
prandata:fix/chown-performance-12043

Conversation

@prandata
Copy link
Copy Markdown

@prandata prandata commented Jan 5, 2026

Summary

Eliminates ~41-minute Docker build delay caused by recursive chown operations on large directories. Files are now created with correct ownership from the start.

Problem

Docker image builds for SWE-bench evaluation take ~41 minutes at step #17 (Dockerfile.j2 lines 225-231) due to:

chown -R openhands:openhands /openhands/poetry && \
chown -R openhands:openhands /openhands/micromamba && \

These directories contain millions of inodes (conda packages, Python virtualenvs). Docker's overlay2 filesystem is notoriously slow for metadata-heavy operations like recursive ownership changes.

Observed build time:

  • Start: 12:27:11
  • End: 13:08:34
  • Duration: 2482.8s (~41 minutes)

Solution

Run micromamba create and micromamba install as the openhands user instead of root. This creates all conda environment files with correct ownership from the start, eliminating the need for post-installation chown -R.

Changes

File Change
Dockerfile.j2:293-297 Add USER openhands before conda operations, USER root after
Dockerfile.j2:226-231 Remove redundant chown -R on poetry and micromamba dirs

Expected Improvement

Metric Before After Change
Step #17 duration ~2500s <10s ~99.6% faster

Breaking Changes

None. The directories end up with the same ownership and permissions. Only the method of achieving that ownership changes.

Testing

  • Verify micromamba create/install works as non-root user
  • Verify poetry virtualenvs are correctly owned by openhands
  • Run SWE-bench evaluation to confirm build time improvement

Related


Note: I posted a validation comment on the issue before submitting this PR. Happy to adjust the approach based on feedback.

Problem:
Docker image builds for SWE-bench take ~41 minutes at step #17 due to
recursive chown operations on /openhands/poetry and /openhands/micromamba.
These directories contain millions of files (conda packages, virtualenvs).

Root Cause:
- micromamba create/install ran as root, creating root-owned files
- Later, chown -R changed ownership to openhands user
- overlay2 filesystem is slow for metadata-heavy operations

Solution:
- Run micromamba create/install as openhands user from the start
- Files are created with correct ownership, no chown needed
- Remove redundant chown -R on poetry and micromamba dirs

Expected improvement: ~2500s → <10s (100x+ faster builds)

Fixes #12043
@malhotra5
Copy link
Copy Markdown
Collaborator

@tofarr @chuckbutkus would you like to review this PR?

@mamoodi mamoodi requested a review from raymyers January 8, 2026 15:26
@raymyers
Copy link
Copy Markdown
Contributor

raymyers commented Jan 8, 2026

Great find, @pdaxt!

@raymyers raymyers merged commit 39f0e6e into OpenHands:main Jan 8, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Excessive Time Spent on chown Operations During SWE-bench Evaluation

4 participants