perf(cli): Batch index adds instead of staging one file at a time - #4056
Merged
Conversation
isomorphic-git re-serializes and rewrites the entire index on every git.add, so staging one path per call costs O(n) per file and O(n^2) overall. On large datasets this dominates the upload: the staging rate decays as 1/n, from ~300 files/min early on to ~30 files/min at 83k files. Collect paths and stage them in batches of 500 instead. annexAdd no longer stages the file itself, leaving that to the caller. Measured with isomorphic-git 1.36.3 on local NVMe, 20k files: per-file add 1173.3s rate decays 8840 -> 541 files/min batched (1000) 6.1s rate flat, ~180k files/min git.add already accepts an array of paths, so this needs no upstream change.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4056 +/- ##
==========================================
- Coverage 48.89% 48.89% -0.01%
==========================================
Files 686 686
Lines 38069 38075 +6
Branches 1894 1897 +3
==========================================
+ Hits 18615 18616 +1
- Misses 19293 19295 +2
- Partials 161 164 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
nellh
approved these changes
Aug 6, 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.
Fixes #4055
Problem
annexAddstages each file with its owngit.add, and isomorphic-gitre-serializes and rewrites the entire index on every call. Staging is therefore
O(n) per file and O(n²) overall.
On a 185k-file dataset the rate fell from ~300 files/min to ~30 files/min by 83k
files, projecting roughly four more days of staging before any transfer started.
Change
Collect paths and stage them in batches of 500.
annexAddno longer callsgit.additself; it returnstrueand the caller batches.git.addalreadyaccepts an array, so no upstream change is required.
Measurement
isomorphic-git 1.36.3, 20,000 files, local NVMe:
192x faster, and the rate no longer decays. Confirmed in production on a 185k-file
dataset: ~200 files/min and falling became ~1200 files/min and steady.
Testing
deno test— 36 passed, 0 faileddeno fmt --checkanddeno lintclean on the changed filesADD_BATCH_SIZEset to 1, 2 and 500 toexercise both the multi-flush and single-flush paths. All produce an identical
repository — that test asserts an exact git object count, so a staging error
would surface.
Note for review
With batching, up to
ADD_BATCH_SIZE - 1files can be staged on disk but not yetrecorded in the index if the process dies mid-run. Staging is idempotent so a rerun
redoes them. 500 is a compromise between that window and the per-flush cost; the
benchmark is already flat by ~2000 files, so a smaller batch would cost nothing
measurable if you would prefer a tighter bound.