perf(mcp): batch git spawns in the worktree transaction (~40→30 per write)#64
Merged
Conversation
Every local write goes through createTransaction, which spawned ~40 git processes for a single content_save. Two behavior-preserving batches: - Commit identity via env: the worktree git instance carries GIT_AUTHOR_*/ GIT_COMMITTER_* instead of two `git config user.*` spawns per transaction (and per mergeBranch). Git honors these for the sync merges and the feature-branch commit alike. - selectiveSync batching: one `git ls-tree` over the changed paths replaces the per-file `cat-file -e` existence loop; one `git checkout HEAD -- <files>` replaces the per-file checkout loop (per-file fallback on error preserves precise skip accounting). Deletions are parallel fs removals. Measured: a 2-locale content_save drops from ~40 git spawns to ~30 (config 2->0, cat-file 5->0, checkout 7->3) and ~1600ms -> ~780ms. selectiveSync scales with file count, so bulk writes benefit most. Behavior unchanged: transaction 15/15, content+model 53/53 green.
✅ Deploy Preview for contentrain-ai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
Every local write (
content_save,model_save,bulk, normalize apply) runs throughcreateTransaction. A single 2-localecontent_savespawned ~40gitsubprocesses; profiling showed the git work is tiny (~0.5s) — the cost is spawn overhead. Two behavior-preserving batches cut it:GIT_AUTHOR_*/GIT_COMMITTER_*in its env instead of twogit config user.*spawns per transaction (and percontentrain_merge). Git honors these for the sync merges and the feature-branch commit alike.selectiveSync— onegit ls-treeover the changed paths replaces the per-filecat-file -eexistence loop; onegit checkout HEAD -- <files>replaces the per-file checkout loop (per-file fallback on error preserves precise skip accounting). Working-tree deletions are parallel fs removals.Measured (single 2-locale content_save, profiled with GIT_TRACE)
configcat-filecheckoutThe
selectiveSyncwin scales with file count, so bulk writes benefit the most.Safety
No behavior change. Verified green:
transaction.test.ts15/15 (covers selectiveSync, auto-merge, mergeBranch),content+model+ core content 53/53.oxlint+tscclean. gc/maintenance auto-runs are intentionally left alone (they operate on the user's real object store).🤖 Generated with Claude Code