perf: Reduce allocations in file hash computation#12102
Open
anthonyshew wants to merge 1 commit intomainfrom
Open
perf: Reduce allocations in file hash computation#12102anthonyshew wants to merge 1 commit intomainfrom
anthonyshew wants to merge 1 commit intomainfrom
Conversation
Deduplicate range-bound string allocations in get_package_hashes —
compute format!("{}/", prefix) and format!("{}0", prefix) once
instead of twice per call (once for ls_tree, once for status). Also
compare using str slices instead of constructing RelativeUnixPathBuf
wrappers for the range bounds.
Use HashMap::entry API in calculate_file_hashes dedup loop to avoid
cloning the HashKey on cache hits. Previously, the key was constructed,
looked up with get(), and on miss cloned again for insert + push. Now
the entry API does one lookup and only clones into unique_keys on miss.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Coverage Report
|
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.
Summary
get_package_hashes— format strings for binary search bounds are computed once and reused for bothls_tree_hashesandstatus_entrieslookups, eliminating 4String+ 4RelativeUnixPathBufallocations per call (440 total across 110 packages)HashMap::entryAPI incalculate_file_hashesdedup loop to avoid cloning theHashKeyon cache hits (the common case in monorepos where multiple tasks share a package)Benchmark (quiet Linux sandbox, 80K-file monorepo, 25 runs)
These are allocation-level improvements — the effect is small on a benchmark dominated by filesystem I/O but the changes remove unnecessary work on the hot path of
calculate_file_hashes(called for every task) andget_package_hashes(called for every package).