Skip to content

perf: parallelize git calls in log for 50-70% speedup - #30

Merged
jondeibel merged 3 commits into
mainfrom
log-optimization
Mar 6, 2026
Merged

jondeibel merged 3 commits into
mainfrom
log-optimization

Conversation

@jondeibel

Copy link
Copy Markdown
Owner

Summary

Rewrites gw log to minimize and parallelize git subprocess calls:

  • Phase 1: Single for-each-ref call gets all branch SHAs and remote tracking info (eliminates per-branch rev-parse)
  • Phase 2: Single bash subprocess runs all merge-bases, commit logs, and behind-counts in parallel using background jobs and temp files
  • From Rust: 4 total subprocesses regardless of branch count (rev-parse --show-toplevel, rev-parse --abbrev-ref HEAD, for-each-ref, one bash script)

Also adds a benchmark harness (bench/log_bench.sh) that creates temp repos at various scales and measures timing + git call counts.

Benchmarks

Repo Branches Before After Speedup
Small test 3 278ms 142ms 49%
Medium test 9 639ms 228ms 64%
Large test 25 1673ms 495ms 70%
Webflow (real monorepo) 5 420ms 175ms 58%

Test plan

  • All 131 tests pass
  • Benchmarked against test repos at small/medium/large scales
  • Profiled against real monorepo (webflow)
  • Verified output matches previous version

🤖 Generated with Claude Code

jondeibel and others added 3 commits March 5, 2026 22:20
Shell script that creates temp repos at small/medium/large scales,
times gw log, and counts git subprocess calls with a wrapper shim.

Baseline: ~20ms per git subprocess, ~3-4 calls per branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rewrites the log command to minimize git subprocess spawns:
- Uses for-each-ref SHAs to eliminate per-branch rev-parse calls
- Batches all merge-base calls into a single bash subprocess
- Batches all git log calls into a single bash subprocess
- Batches rev-list --count for behind detection

Benchmarks (25 branches): 1673ms -> 1171ms (30% faster)
Git subprocess calls: 79 -> 53 (from Rust: 5 fixed + batched)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rewrites the batch data-gathering to use one bash subprocess that runs
all merge-bases, logs, and behind-counts in parallel using background
jobs and temp files. Output is collected sequentially after all jobs
complete to avoid interleaving.

From Rust: 4 subprocesses total (2 rev-parse, 1 for-each-ref, 1 bash).

Benchmarks vs original:
  Small  (3 branches):  278ms -> 142ms (49% faster)
  Medium (9 branches):  639ms -> 228ms (64% faster)
  Large  (25 branches): 1673ms -> 495ms (70% faster)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jondeibel
jondeibel merged commit 870cf73 into main Mar 6, 2026
6 checks passed
@jondeibel
jondeibel deleted the log-optimization branch March 6, 2026 03:41
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