refactor(core): significantly speed up slow revert functionality#20551
refactor(core): significantly speed up slow revert functionality#20551natewill wants to merge 13 commits intoanomalyco:devfrom
Conversation
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, the current PR (#20551) appears to be the primary result in most searches. The other related PRs found are:
However, none of these appear to be duplicates addressing the same optimization (batching by snapshot hash to speed up Snapshot.revert). PR #16103 touches on parallelizing git operations, but that's a different scope. No duplicate PRs found |
0badd89 to
921c809
Compare
| } | ||
| } | ||
|
|
||
| const revertSingle = Effect.fnUntraced(function* (hash: string, file: string) { |
There was a problem hiding this comment.
revertSingle is the same functionality as the revert function that is in the current code. We use this as a fallback if the batching doesn't work for some reason or the snapshot hash only has one reverted file in it
| } | ||
| continue | ||
| } | ||
|
|
There was a problem hiding this comment.
Here, we only checkout files that exist in this snapshot; files missing from the tree should be removed. The old code did the same thing but individually.
Refactor comments for clarity and consistency in index.ts.
Issue for this PR
Closes #20550
Type of change
What does this PR do?
This PR speeds up
Snapshot.revertfor large revert operations.Currently, revert handles files one at a time. In the worst case, that means up to
2ngit subprocesses fornfiles: onegit checkoutper file, and onegit ls-treeper file when checkout fails. Because each subprocess has overhead (10-20ms per file), revert gets very slow as file count grows.This change batches files by snapshot hash and processes them in chunks. In the common case, that reduces the work from
2ngit subprocesses to two batchedgit ls-treeandgit checkoutcalls per 100 file chunks, while preserving the existing single-file path as a fallback if a batched operation fails.In local testing on my machine,
Snapshot.revertfor a 300-file revert dropped from 8.72s to 96ms, which is about a 90x speedup.This improves the file rollback portion of revert specifically. The remaining time in full session revert is still dominated by diff generation after rollback, which can be lengthy.
How did you verify your code works?
Screenshots / recordings
Not UI change
Checklist