Skip to content

perf: fix slow reads of files written in small pieces - #30

Merged
tofarr merged 1 commit into
mainfrom
perf-extent-read-path
Dec 3, 2026
Merged

tofarr merged 1 commit into
mainfrom
perf-extent-read-path

Conversation

@tofarr

@tofarr tofarr commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Why

Reading a file written with many small write() calls was very slow. Git writes its pack file in 4 KiB pieces. Fusey stored one extent for each write, so the 746 MB pack file had about 182,000 extents. Every read copied the whole extent list and scanned it from the start. In the benchmark from #28, reading a fresh clone and npm install took 1,098 s on fusey and 3 s on a regular filesystem.

This PR makes four changes:

  • WriteExtent merges a write into the previous extent when it continues it in the same chunk. It also keeps each file's extents sorted and non-overlapping.
  • FileHandle.Read calls a new ExtentsInRange. It uses a binary search and copies only the extents that overlap the read.
  • ChunkStore.Read copies only the requested bytes from the active chunk. It used to copy the whole buffer, up to 64 MiB, on every read.
  • The CBOR decoder limits for arrays and maps are raised from 131,072. A file with more extents than that wrote an index that could not be loaded again, so the mount failed with exceeded max number of elements.

Snapshots saved before this change may have unsorted extents. They are sorted when loaded, so existing mounts keep working. On-disk and wire formats do not change.

Validation

  • Benchmark from perf: add git clone + npm install benchmark (regular fs vs fusey mount) #28, full clone plus npm install — the read phase fell from 1,098 s to 70 s. The 746 MB pack file alone fell from 75 s to 2.5 s. status fell from 1.7 s to 0.4 s.
  • Remaining gap — read is still about 24x slower than a regular filesystem, and install about 13x. A profile of the node_modules read shows the daemon about 73% idle. The time is per-file FUSE overhead, which this PR does not change.
  • Randomised test — 2,000 random overlapping writes are compared byte by byte with a model. The extents stay sorted and non-overlapping after every write.

This PR was drafted by an AI agent on behalf of the user.

@tofarr can click here to continue refining the PR

…eeded

- WriteExtent merges a write into the previous extent when it continues it
  in the same chunk, and keeps each file's extents sorted and non-overlapping.
  A file written in 4 KiB pieces (a git pack) went from ~182k extents to a few.
- FileHandle.Read asks the index for only the extents overlapping the read
  (ExtentsInRange, binary search) instead of copying and scanning the whole
  extent list on every read.
- ChunkStore.Read copies only the requested bytes from the active chunk
  instead of the whole (up to 64 MiB) buffer.
- Raise the CBOR decoder array/map limits so a large index can be reloaded.

Co-authored-by: openhands <openhands@all-hands.dev>

@hieptl hieptl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙏

@tofarr
tofarr merged commit a78eea1 into main Dec 3, 2026
1 check 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.

2 participants