refactor(core): speed up diff calculation significantly #20731
Open
natewill wants to merge 5 commits intoanomalyco:devfrom
Open
refactor(core): speed up diff calculation significantly #20731natewill wants to merge 5 commits intoanomalyco:devfrom
natewill wants to merge 5 commits intoanomalyco:devfrom
Conversation
natewill
commented
Apr 2, 2026
| const diffFull = Effect.fnUntraced(function* (from: string, to: string) { | ||
| return yield* locked( | ||
| Effect.gen(function* () { | ||
| const catFile = Effect.fnUntraced( |
Contributor
Author
There was a problem hiding this comment.
We can’t use the normal git() helper here because git cat-file --batch needs us to write refs to stdin and read raw stdout bytes back, and the normal helper just treats everything like plain text.
natewill
commented
Apr 2, 2026
| const out = new Map<string, string>() | ||
| const dec = new TextDecoder() | ||
| let i = 0 | ||
| for (const ref of refs) { |
Contributor
Author
There was a problem hiding this comment.
Each batch entry is either "<ref> missing" for added/deleted files or "<id> blob <byte_size>\n<file_contents>\n".
kitlangton
added a commit
that referenced
this pull request
Apr 4, 2026
Derived from #20731. Co-authored-by: Nate Williams <50088025+natewill@users.noreply.github.com>
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.
Issue for this PR
Closes #20734
Closes #11486
Type of change
What does this PR do?
This PR speeds up the
Snapshot.diffFullfunction, somewhat similar to how #20564 and #20551 speed uprevert.Currently,
diffFullhandles one file at a time when when loading blob contents. This means fornfiles it's spawning2ngit processes forgit show from:andgit show to:. Similar to the old revert function, each git process has significant overhead (10-20ms) per process, making the entire function very slow.This change batches files by using
git cat-file --batchto do all of the work forgit showin one git command. This reduces the work forgit showfrom2nto a constant factor of1, while preserving the existing single-file path as a fallback if the batched operation fails.On my machine, a
Snapshot.diffFullfor a 1000 file diffFull went 13.68s to ~0.34s which is a 40x speed up. This function is ran frequently in the application, making this speedup worthwhile.How did you verify your code works?
bun testtests forSnapshot.diffFull(), including:diffFullscenariosAll of these passed
Screenshots / recordings
Not a UI change
Checklist