perf(snapshot): add mutex lock, incremental add, and batched revert#8445
Merged
Conversation
Contributor
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)WARNING
Other Observations (not in diff)Previously reported non-ASCII batched revert issue is resolved via Files Reviewed (2 files)
Reviewed by gpt-5.4-20260305 · 221,966 tokens |
b450bb9 to
0c1dfa1
Compare
be6aa4c to
af3dea0
Compare
Port snapshot optimizations from upstream OpenCode to reduce git process spawning and prevent concurrent corruption: - Per-gitdir mutex lock (upstream #17878, v1.3.0): serializes concurrent snapshot operations to prevent race conditions - Incremental git add (upstream #17878, v1.3.0): replaces naive `git add .` with diff-files + ls-files + size filtering, skipping files >2MB - Batched revert (upstream #20564, v1.3.14): groups up to 100 files per git checkout call with path-conflict detection, falling back to single-file revert on failure Benchmarks (200 files): - revert: 2,851ms → 191ms (15x faster, 8x fewer git processes) - concurrent track: 2/5 succeed → 5/5 succeed (corruption fixed)
af3dea0 to
a010010
Compare
imanolmzd-svg
approved these changes
Apr 7, 2026
This was referenced Apr 9, 2026
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.
Port snapshot optimizations from upstream OpenCode to reduce git process spawning and prevent concurrent corruption.
Relates to #8379
Port snapshot optimizations from upstream OpenCode to reduce git process spawning and prevent concurrent corruption:
git add .with diff-files + ls-files + size filtering, skipping files >2MBBenchmarks (200 files):
Context
Users reported high RAM usage and excessive git processes, especially on Windows with Agent Manager. A potential root cause is the snapshot module spawning many concurrent/redundant git processes during track, revert, and diff operations. OpenCode upstream has addressed these with Effect-TS based optimizations, this PR ports the key improvements as plain async/Promise code without adopting the Effect runtime until we are able merge newest upstream releases.
Implementation
Three optimizations ported from upstream, all contained in packages/opencode/src/snapshot/index.ts:
Local Adhoc Benchmarks (200 files)
Screenshots
N/A -- backend optimization, no UI changes.
How to Test
test/snapshot/snapshot.test.ts test/kilocode/snapshot-cache.test.ts
Get in Touch