GeezerVison is showing github.com — refactor(core): significantly speed up slow revert functionality by natewill · Pull Request #20551 · anomalyco/opencode
Conversation
natewill
commented
Apr 1, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #20550
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
This PR speeds up Snapshot.revert for large revert operations.
Currently, revert handles files one at a time. In the worst case, that means up to 2n git subprocesses for n files: one git checkout per file, and one git ls-tree per 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 2n git subprocesses to two batched git ls-tree and git checkout calls 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.revert for 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?
- Verified locally with mixed revert scenarios covering modified existing files, deleted existing files, newly created files, and overlapping files across patches.
- Verified the real session revert flow restores the worktree correctly for mixed file changes.
- Ran bun typecheck in packages/opencode.
Screenshots / recordings
Not UI change
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Hey! Your PR title perf(core): significantly speed up slow revert functionality doesn't follow conventional commit format.
Please update it to start with one of:
feat: or feat(scope): new feature
fix: or fix(scope): bug fix
docs: or docs(scope): documentation changes
chore: or chore(scope): maintenance tasks
refactor: or refactor(scope): code refactoring
test: or test(scope): adding or updating tests
Where scope is the package name (e.g., app, desktop, opencode).
See CONTRIBUTING.md for details.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
natewill
changed the title
perf(core): significantly speed up slow revert functionality
refactor(core): significantly speed up slow revert functionality
Apr 1, 2026
|
|
}
|
|
|
}
|
|
|
|
|
|
const revertSingle = Effect.fnUntraced(function* (hash: string, file: string) {
|
natewill
Apr 1, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
natewill
Apr 1, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Refactor comments for clarity and consistency in index.ts.
|
Automated PR Cleanup
Thank you for contributing to opencode.
Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.
This PR was closed because it matched the following cleanup criteria:
- The PR was created more than 1 month ago
- The PR had fewer than 2 positive reactions
- Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR
PRs created within the last month are not affected by this cleanup.
If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.
Thanks again for taking the time to contribute.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
[BUG} revert is very slow
Uh oh!
There was an error while loading. Please reload this page.
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.
|