Skip to content

perf(cli): apply bundle via git fetch + git merge --ff-only#317

Closed
worstell wants to merge 1 commit into
mainfrom
feat/bundle-fetch-merge
Closed

perf(cli): apply bundle via git fetch + git merge --ff-only#317
worstell wants to merge 1 commit into
mainfrom
feat/bundle-fetch-merge

Conversation

@worstell
Copy link
Copy Markdown
Contributor

Replaces git pull --ff-only <bundle> <branch> in cachew git restore's bundle-apply path with an explicit git fetch + git merge --ff-only FETCH_HEAD pair.

Why

git pull runs two implicit subcommands that add no value for a one-shot bundle apply:

  • git rev-list --objects --stdin --not --exclude-hidden=fetch --all — connectivity check across all local refs
  • git maintenance run --auto — background gc/repack heuristic; can trigger surprise pack rewrites during a hot bootstrap path

Observability

Emits separate cachew.git_fetch_seconds and cachew.git_merge_seconds span attributes so future work can attribute bundle-apply cost between fetch vs working-tree update. Today the working-tree update (cold git merge on a fresh tar-extracted repo) dominates by ~30x.

Measured impact

On a staging cachew-bench workstation against squareup/cash-server (5.5 GiB snapshot, 290 KiB bundle, 13 commits ahead):

bundle apply (median of 3)
before 14.95 s
after 14.41 s

~300 ms wall-clock; the rest is the cold git merge itself reading every stat-dirty index entry on the fresh extract. This PR is mainly about predictability and instrumentation — the headline cold-merge cost needs a separate (server-side) fix.

Replaces `git pull --ff-only <bundle> <branch>` in cachew git restore's
bundle-apply path with an explicit `git fetch` + `git merge --ff-only
FETCH_HEAD` pair.

`git pull` runs two implicit subcommands that add no value for a
one-shot bundle apply:
- `git rev-list --objects --stdin --not --exclude-hidden=fetch --all`
  (connectivity check across all local refs)
- `git maintenance run --auto` (background gc/repack heuristic) — can
  trigger surprise pack rewrites during a hot bootstrap path

The new path also emits separate cachew.git_fetch_seconds and
cachew.git_merge_seconds span attributes so future work can attribute
bundle-apply cost between fetch vs working-tree update.

Measured on a staging cachew-bench workstation against
squareup/cash-server (5.5 GiB snapshot, 290 KiB bundle, 13 commits
ahead): bundle-apply wall-clock improves ~300ms (14.95s -> 14.41s
median over 3 runs). The cold `git merge` itself dominates bundle
apply cost on a fresh extract; this PR is mainly about predictability
and instrumentation, not raw wall-clock.

Amp-Thread-ID: https://ampcode.com/threads/T-019e41af-0a15-718d-a9d8-e26df6071f9b
Co-authored-by: Amp <amp@ampcode.com>
@worstell worstell closed this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant