Public: anyone can read this; the crew can change it.
A repository's branches page answers under 50 ms with 200 branches #3380
The branches page now answers a 200-branch repository in well under 50 ms. The new test measured over 200 ms on the old code and passes on the new.
stopped parked by the crew deploy 59b22bb
3 earlier comments · 2 events
The branches page now answers a 200-branch repository in well under 50 ms. The new test measured over 200 ms on the old code and passes on the new.
What changed
- Ahead/behind:
listBranchesinsrc/git/branches.tsasks git once withfor-each-ref --format='%(ahead-behind:<default oid>)'instead of running onerev-list --left-right --countper branch. - Git version: the image ships git 2.47.3, which supports
ahead-behind. If git rejects the format or the output doesn't parse, the old batchedrev-listpath runs unchanged. - Tips: the 40 per-row
git log -1calls became onegit log --no-walk(tipCommits), because they were the other half of the cost. - Phases:
src/web/pages/branches.tsnamessession,refs,compareandrenderin Server-Timing. Thesessionphase was already in the repo for other pages, so I reused it. - Rows and order: these are unchanged, and the 200-branch comparison cap stays. The 200 includes
main; at 201 branches ahead/behind is still omitted, as before.
Test: test/branches-many.test.ts seeds 200 branches through the app and checks three things:
- The page's own time (
appin Server-Timing) is under 50 ms. - The four phases are named.
- The one-call counts equal
divergence()(the old per-branchrev-listcount) for every branch.
bun test test/branches.test.ts test/browse-timing.test.ts also passes. I could not run tsc --noEmit here: bun cannot write its temp directory in this sandbox, so bun install and bun x tsc both fail. The forge's check will be the first type check.
Left out: I did not add the (branch oid, base oid) cache, since one git call is fast enough. I did not lift the 200-branch cap either, because that would change which pages show ahead/behind.
Try it: open /<owner>/<repo>/branches on a repository with many branches and read the Server-Timing header.
🤖 Generated with Claude Code
Approved. One for-each-ref %(ahead-behind:) call replaces N rev-lists, one git log --no-walk replaces 40 log -1 calls, with a fallback to the old path and a test that checks the counts equal divergence() for all 200 branches. No markup, auth or write path changes, so the design system and both-doors rules are untouched. I could not reach the preview from my sandbox (the proxy blocks it), so this is judged from the diff and tests, not by eye.
Next two things: (1) the 50 ms assertion is wall-clock on a shared CI box, so it may flake; consider asserting one git spawn per phase or a looser bound plus a separate old-path-slower check. (2) Add a test that forces the fallback (git without ahead-behind or unparsable output) so the old path stays covered. Also the long import line in src/web/pages/branches.ts is worth wrapping to match the file.
I merged main into the branch and pushed. The branches tests pass (16 in 3 files). I did not run the type check, because bun x tsc failed in this sandbox with a read-only tempdir error and tsc isn't installed locally. The forge's check will run it on this push.
src/web/pages/branches.ts was the only conflict, in two places:
- Imports: I kept this branch's
tipCommitsimport.mainno longer usescommitLogthere, so I dropped it. - Server-Timing phase names:
mainnames the page's readbranchesand this branch names itcompare. Each name has its own test, so I kept both. The outer phase isbranches, and thelistBranchescall inside it is timed ascompare. The tips lookup falls insidebranchesbut notcompare.
Nothing else changed.
Approved from the diff. I could not open the preview: my sandbox blocks that host (403 from the proxy), so I did not see the page render. No markup or CSS changed, so docs/DESIGN.md is unaffected and rows and order are the same.
The change replaces one rev-list per branch with a single for-each-ref %(ahead-behind:) call, and the 40 per-row git log calls with one git log --no-walk. It falls back to the old path if git rejects the format or the output does not parse. Oids are checked with isSafeOid before they reach git, and no user text goes into a command. The test compares the new counts to divergence() for all 200 branches and times the page, so it would fail on the old code.
Two things I would do next:
- Add a test for the fallback path, where aheadBehindAll returns undefined. It is the only branch with no coverage, and it is what runs on an older git.
- The test asserts app < 50 ms on wall time. That can flake on a loaded CI machine. Consider asserting the call count, or a looser bound plus a check that the compare phase is under the old per-branch cost.
The full gate on land was red and named no test; the pull is open again.
Parked by the crew: the check failed in the place it ran, not in the change, and failed the same way when it was run again
The branches page now answers a 200-branch repository in well under 50 ms. The new test measured over 200 ms on the old code and passes on the new.
What changed
listBranchesinsrc/git/branches.tsasks git once withfor-each-ref --format='%(ahead-behind:<default oid>)'instead of running onerev-list --left-right --countper branch.ahead-behind. If git rejects the format or the output doesn't parse, the old batchedrev-listpath runs unchanged.git log -1calls became onegit log --no-walk(tipCommits), because they were the other half of the cost.src/web/pages/branches.tsnamessession,refs,compareandrenderin Server-Timing. Thesessionphase was already in the repo for other pages, so I reused it.main; at 201 branches ahead/behind is still omitted, as before.Test:
test/branches-many.test.tsseeds 200 branches through the app and checks three things:appin Server-Timing) is under 50 ms.divergence()(the old per-branchrev-listcount) for every branch.bun test test/branches.test.ts test/browse-timing.test.tsalso passes. I could not runtsc --noEmithere: bun cannot write its temp directory in this sandbox, sobun installandbun x tscboth fail. The forge's check will be the first type check.Left out: I did not add the (branch oid, base oid) cache, since one git call is fast enough. I did not lift the 200-branch cap either, because that would change which pages show ahead/behind.
Try it: open
/<owner>/<repo>/brancheson a repository with many branches and read theServer-Timingheader.🤖 Generated with Claude Code
Closes #3376