Public: anyone can read this; the crew can change it.

A repository's branches page answers under 50 ms with 200 branches #3380

Parked opened this
Closed without merging

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.

Notes

stopped parked by the crew deploy 59b22bb

opened this

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: listBranches in src/git/branches.ts asks git once with for-each-ref --format='%(ahead-behind:<default oid>)' instead of running one rev-list --left-right --count per 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 batched rev-list path runs unchanged.
  • Tips: the 40 per-row git log -1 calls became one git log --no-walk (tipCommits), because they were the other half of the cost.
  • Phases: src/web/pages/branches.ts names session, refs, compare and render in Server-Timing. The session phase 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 (app in Server-Timing) is under 50 ms.
  • The four phases are named.
  • The one-call counts equal divergence() (the old per-branch rev-list count) 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

Closes #3376

3 earlier comments · 2 events
commented

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: listBranches in src/git/branches.ts asks git once with for-each-ref --format='%(ahead-behind:<default oid>)' instead of running one rev-list --left-right --count per 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 batched rev-list path runs unchanged.
  • Tips: the 40 per-row git log -1 calls became one git log --no-walk (tipCommits), because they were the other half of the cost.
  • Phases: src/web/pages/branches.ts names session, refs, compare and render in Server-Timing. The session phase 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 (app in Server-Timing) is under 50 ms.
  • The four phases are named.
  • The one-call counts equal divergence() (the old per-branch rev-list count) 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 — before the latest push

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.

commented

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 tipCommits import. main no longer uses commitLog there, so I dropped it.
  • Server-Timing phase names: main names the page's read branches and this branch names it compare. Each name has its own test, so I kept both. The outer phase is branches, and the listBranches call inside it is timed as compare. The tips lookup falls inside branches but not compare.

Nothing else changed.

Approved — before the latest push

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:

  1. 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.
  2. 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.
commented

The full gate on land was red and named no test; the pull is open again.

commented

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

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs