Repository navigation
perf: fix slow reads of files written in small pieces - #30
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 andnpm installtook 1,098 s on fusey and 3 s on a regular filesystem.This PR makes four changes:
WriteExtentmerges 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.Readcalls a newExtentsInRange. It uses a binary search and copies only the extents that overlap the read.ChunkStore.Readcopies only the requested bytes from the active chunk. It used to copy the whole buffer, up to 64 MiB, on every read.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
npm install— thereadphase fell from 1,098 s to 70 s. The 746 MB pack file alone fell from 75 s to 2.5 s.statusfell from 1.7 s to 0.4 s.readis still about 24x slower than a regular filesystem, andinstallabout 13x. A profile of thenode_modulesread shows the daemon about 73% idle. The time is per-file FUSE overhead, which this PR does not change.This PR was drafted by an AI agent on behalf of the user.
@tofarr can click here to continue refining the PR