Skip to content

perf(context): batch blob reads + single-flight the workspace build#12

Merged
casabre merged 1 commit into
mainfrom
feat/workspace-batch-singleflight
Jul 4, 2026
Merged

perf(context): batch blob reads + single-flight the workspace build#12
casabre merged 1 commit into
mainfrom
feat/workspace-batch-singleflight

Conversation

@casabre

@casabre casabre commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Implements the two items deferred from the last review — by making the discovery build async.

#2 — one process instead of N

A build now reads all needed blobs (conventions + up to 200 source files) in a single git cat-file --batch process, instead of one git show per file.

  • defaultGitRunner switches from execFileSync to spawn (async, binary-safe, feeds refs on stdin) — also removes the fixed 1 MB/64 MB maxBuffer ceiling.
  • parseBatch frames the records by byte size (multi-byte safe); a missing blob is skipped, not fatal.

#5 — single-flight

getContextPack is now genuinely async, so concurrent first-callers on the same HEAD SHA share one in-flight build rather than both running it. (Previously moot because _build was synchronous — now real and tested.)

Tests

parseBatch and defaultGitRunner are unit-tested directly (present / missing / truncated / multi-byte; non-zero exit; spawn error), plus single-flight dedup, the empty-batch short-circuit, and the default spawn-backed path. Docs updated to reflect batched/async reads.

Gates

typecheck ✅ · lint ✅ · test:coverage ✅ (416 tests, 100%) · build ✅.

🤖 Generated with Claude Code

Implement the two deferred review items by making the discovery build async:

- Batched reads (#2): a build now reads every needed blob (conventions +
  source files) in ONE `git cat-file --batch` process instead of one `git show`
  per file. defaultGitRunner switches to spawn (async, binary-safe, feeds refs
  on stdin) and parseBatch frames the records by byte size. This removes the
  N-subprocess fan-out and the fixed maxBuffer ceiling.
- Single-flight (#5): getContextPack is now genuinely async, so concurrent
  first-callers on the same HEAD SHA share one in-flight build instead of both
  running it. (Previously moot because _build was synchronous.)

A source file missing from the batch is skipped, not fatal. parseBatch and
defaultGitRunner are unit-tested directly (present/missing/truncated/multi-byte;
exit-code and spawn-error paths). Docs updated to reflect the batched/async read.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@casabre casabre merged commit f96bec0 into main Jul 4, 2026
10 checks passed
@casabre casabre deleted the feat/workspace-batch-singleflight branch July 4, 2026 20:34
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