perf(server): scan checkpoint ls-files output by record, not by byte #26687
main fromrefs/pull/26687/head·opened View on GitHubEvery turn-end checkpoint capture streams git ls-files --full-name --sparse -v -z for the whole repository through an onStdoutChunk callback, which looped over every byte in JS with for…of. On large repositories this blocks the server event loop for tens of milliseconds per turn.
The callback now jumps between NUL record terminators with Uint8Array.indexOf, checks only the tag byte at the start of each record, and copies record bytes only for skipped (S) records under sparse checkout. Parser state still carries across chunks, so records split between chunks behave as before. specialFlags and skippedPaths come out the same.
Measurements#
Harness: the old and new callbacks copied verbatim into a scratch module and fed identical 64 KiB chunks of ls-files -v -z output. 5 warmup rounds, then 9 interleaved runs per implementation, median reported. --expose-gc --max-semi-space-size=512 so heapUsed deltas track allocation. Node 24.18, macOS (Apple Silicon).
| Input | Before | After |
|---|---|---|
| Real repo (this checkout, 28,875 files, 2.1 MB) | 10.19 ms | 0.93 ms (11x) |
| Synthetic 100k files, 4.8 MB | 21.4 ms, 15.7 MB heap | 2.7 ms, 13 KB heap |
| Synthetic 300k files, 14.5 MB | 61.8 ms | 7.0 ms |
What limits the new number: native indexOf scanning for NUL across the buffer, which is memory bandwidth bound. The JS work is now one tag check per record.
Benchmark script (real repo)
// lsfiles.mjs exports oldScanner/newScanner: the old and new callback bodies verbatim.
import { spawnSync } from "node:child_process";
import { oldScanner, newScanner } from "./lsfiles.mjs";
const cwd = process.argv[2];
const out = spawnSync("git", ["ls-files", "--full-name", "--sparse", "-v", "-z"], { cwd, maxBuffer: 1 << 30 }).stdout;
const chunks = []; for (let o = 0; o < out.length; o += 65536) chunks.push(out.subarray(o, o + 65536));
const run = (make) => { const s = make(false); for (const c of chunks) s.onStdoutChunk(c); return s.result(); };
for (let w = 0; w < 5; w++) { run(oldScanner); run(newScanner); }
const t = { old: [], new: [] }, a = { old: [], new: [] };
for (let k = 0; k < 9; k++) for (const [n, m] of [["old", oldScanner], ["new", newScanner]]) {
gc(); const h = process.memoryUsage().heapUsed; const t0 = performance.now(); run(m);
t[n].push(performance.now() - t0); a[n].push(process.memoryUsage().heapUsed - h);
}
const med = (x) => x.toSorted((p, q) => p - q)[x.length >> 1];
for (const n of ["old", "new"]) console.log(n, med(t[n]).toFixed(2), "ms", med(a[n]), "B heap");
Validation#
GitVcsDriver.test.ts: 56/56 pass, including the existing sparse, skip-worktree, assume-unchanged, and split-record capture cases. (With my global git config, one unrelated remote-URL test fails because of aurl.insteadOfrewrite. It passes withGIT_CONFIG_GLOBAL=/dev/null.)- Differential fuzz, old vs new: 20,000 random byte streams × sparse on/off, random 1–6 byte chunk splits, empty records, invalid UTF-8, trailing
/, lowercase/S/Htags, missing final NUL. IdenticalspecialFlagsandskippedPathsevery time. vp run check:changed: format, lint, knip, and typecheck pass.
Not checked: Windows. The change is pure byte scanning, so nothing platform-specific is involved.
Authored with Claude Opus 5.5 via the Claude Code harness in T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
988e364Macroscope's review found this PR approvable — Checkpoint capture now scans Git output by NUL-delimited record to reduce processing overhead in large repositories. The change retains existing sparse-checkout handling and temporary-index safeguards without changing product defaults.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 9826dbb
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
67786b8d-49ad-4498-a110-bcaa5e143db2
Commits-
Reviewing files that changed from the base of the PR and between 9826dbb9904b2591bfbf60d1317486b59132f56b and 988e36428335886bd7399fd5f931621ef3477405.
Files selected for processing: 1-
apps/server/src/vcs/GitVcsDriver.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
Walkthrough
-
The checkpoint index scan now uses
indexOfto locate NUL delimiters. It retains checks for special index flags, collection of sparse-checkout skipped paths, and detection of non-UTF-8 paths.Changes: Git index scan
Priority:Layer / File(s) Summary Scan NUL-delimited index records
apps/server/src/vcs/GitVcsDriver.tsThe stdout scan uses indexOfto advance between NUL-delimited records. It retains special-flag checks and sparse-checkout skipped-record byte collection. LowEstimated code review effort: 2 (Simple) | ~10 minutes
Change: Refactor
Suggested reviewers:
juliusmarminge
Merge Risk:
Minimal · up to988e3-
No merge-blocking issue was found in the checkpoint scan update.
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check The description covers the problem (per-byte JS loop blocking the event loop on large repos), the change (indexOf-based NUL scanning, tag-byte check, sparse skipped-record copy), measurements, and val… Add the 'Scope and approval' section. Link the triaged bug issue or the discussion with the maintainer approval comment. If no issue exists, explain why this focused perf fix qualifies as a very small, obvious change under the template's ex… Passed checks: 3 passed-
Check name Status Explanation Title check The title names the main change: the checkpoint ls-files output scan now steps between NUL records instead of checking every byte. It uses the conventional commit format and matches the raw summary an… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title names the main change: the checkpoint ls-files output scan now steps between NUL records instead of checking every byte. It uses the conventional commit format and matches the raw summary and objectives. It is 68 characters, which is within a normal title length.
-
Full details: Description check
-
Explanation
The description covers the problem (per-byte JS loop blocking the event loop on large repos), the change (indexOf-based NUL scanning, tag-byte check, sparse skipped-record copy), measurements, and validation. It follows the template's Problem, Change, and Verification intent. The 'Scope and approval' section is missing: it has no linked triaged issue or maintainer-approved discussion, and no explanation of why the change qualifies without one. The Verification section is strong, and it names the test run, fuzzing, and the unchecked Windows case.
Resolution
Add the 'Scope and approval' section. Link the triaged bug issue or the discussion with the maintainer approval comment. If no issue exists, explain why this focused perf fix qualifies as a very small, obvious change under the template's exemption. The rest of the description can stay as written. The template also asks for the model and harness used, and the description already includes this.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
@juliusmarminge ready for review. Checkpoint capture's
ls-files -v -zscan went from 10.2 ms to 0.93 ms on a real 28.9k-file repo (about 11x), with a differential fuzz against the old scan. Related to #21328 and #9661 S3 only in touching the same capture path; it does not change what git re-hashes. CI workflows on this fork PR showaction_required, so they are waiting on a maintainer to approve the run. CodeRabbit and Macroscope are done with no open findings.Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Closing: this is covered by #21329, which landed. Reopen if a needed part is still missing.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes