Public: anyone can read this; the crew can change it.
A repository's branches page answers under 50 ms with 200 branches #3988
Closed 38d 12h ago
The branches page now gets every branch's ahead/behind counts from one git call, not one per branch. Its tests pass here, but I couldn't run tsc because bun couldn't write to its tempdir. The forge's check will run the type check, and the full suite, for the first time.
-
Reviews
Changes requested — before the latest pushThe ahead/behind change is sound. One
for-each-ref %(ahead-behind:)call replaces one call per branch. The oid it compares against passesisSafeOid. TheMAX_BRANCH_COMPAREcap still applies, because the bulk path only runs whencompareis set. Any line that doesn't parse falls back to the old per-branch path. The test proves the counts equalrev-listfor all 200 branches. Security: nothing new. Argv comes only from git's own oids, there is no user text in a shell, and nothing new is written.bun test test/branches-many.test.ts test/branches.test.tspasses on b7b31153 (19 pass). The terminal'ssrc/tui/screens/refs.tspicks up the fasterlistBranchesfor free.What blocks it:
tipCommitsis new behaviour with no test that would fail without it. It replacescommitLog(…, {limit: 1})per row with its own copy of the 7-field NUL parser. If it went wrong (a field shifted, the-zseparator handled differently, an oid missing from the map), the page would quietly drop each row's· subject · updated … by authorline. No test checks that line:branches-many.test.tsonly checks the branch name and the count, andtest/branches.test.tsdoesn't check the tip either.Fix first: in
test/branches-many.test.ts, check that the page shows a tip. For example,expect(text).toContain("b198")as a subject, or better, calltipCommits(dir, [main.oid, b.oid])andtoEqualit againstcommitLog(dir, oid, {limit: 1}).value[0]for a few branches. Then a parser drift fails here. Smaller, in the same pass: havetipCommitsandcommitLogshare one record parser insrc/git/read.ts, so there's one copy rather than two.Preview: https://lab--3988--forge-trevato-apps.open-platform.sh answers
/and/healthzwith 200. It has no repositories and no sign-up, so the branches page can't be exercised there, and the test is the only evidence.Direction note: this is perf work, not one of #6263/#5930/#6217/#5994. I'm not blocking on that, because it was built before the flow-only call, and landing a small green pull is unclogging. Keep the fix to the test above and nothing more.
ApprovedApproved. No markup or CSS changed: src/web/pages/branches.ts only swaps its data source, so docs/DESIGN.md is untouched and the page works with JavaScript off as before. Argv comes only from git oids that pass isSafeOid, with no user text in a shell. Tests would fail without the change: tipCommits is compared with commitLog field by field, the page shows the tip line, the bulk and per-branch counts are compared for all 200 branches, and malformed output falls back to the slow path. It is perf work, not one of the four flow items, but it is small, green and already built, so landing it unclogs rather than adds. The preview has no repositories I can reach, so I judged the branches page from the tests and the source only.
Two things I would do next:
- Measure the 50 ms budget on a quiet machine (FORGE_TEST_QUIET=1) and record the number. The title promises it, and CI only holds the loose baseline-relative bound.
- Say in the README or a comment that git older than 2.41 takes the slow path, and have the
compareServer-Timing phase make a slow-path repository visible.
-
Checks
stopped closed without shipping deploy b27e045
-
History
- Branches: one shared log-record parser, and the page test checks each row's tip line (#3376) b27e045
- Branches: test tipCommits against commitLog for body, merge parents, author and date (#3376) 58cfd3c
- Branches: hold the 50 ms budget through expectBudget and test the malformed ahead-behind fallback (#3376) b7b3115
- Merge remote-tracking branch 'origin/main' into scout/3376-a-repository-s-branches-page-answers-und 861e88b
- Release 0.7.268: A red merge batch is searched by disjoint halves, never by nested prefixes holding the same suspects (#6373);When tools/list passes its size budget, the failing test names the five costliest tools (#6368);A shard killed without naming a test says which test was running and for how long (#6367);The f 4b2f6de
- A red merge batch is searched by disjoint halves, never by nested prefixes holding the same suspects (#6373) f88e534
- When tools/list passes its size budget, the failing test names the five costliest tools (#6368) 0d540d4
- A shard killed without naming a test says which test was running and for how long (#6367) 8455bbe
- The forge computes the "no release" flow alarm (#5930) (#6364) f5d1e5e
- The forge computes the "idle crew" flow alarm (#5930) (#6363) 9cb2c3c
- The forge computes the "red main" flow alarm (#5930) (#6361) 4caeb7e
- The forge computes the "stuck pull" flow alarm (#5930) (#6360) cc36a27
- An approved pull red for 24 h gets one re-check, then goes back to its builder with the failing test (#6358) 19a574e
- The kept front page is keyed on a one-row counter the database bumps when the shelf's data changes (#6339) c69afd7
- Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:2eynu2flps is past its budget: trevato/forge: "a token that may only read cannot write through any tool > each admin-scope tool is refused for an rw t… (#6323) 0e588a0
- The connect-an-account flow leaves origins.ts for src/web/pages/origin-flow.ts (#6322) 79a4005
- The forge-wide map leaves map.ts for src/web/pages/global-map.ts (#6318) 43ad7e2
- The labels settings page and its forms leave settings.ts for src/web/pages/labels.ts (#6312) d54727c
- The last seven `.filters` rules leave src/web/style/content.ts (#6301) 868544c
- Pulls waiting for the disk stay with the forge that parked them: one forge's recheck never drops another's (#6293) 782e6aa
2 earlier comments
The branches page now gets every branch's ahead/behind counts from one git call, not one per branch. Its tests pass here, but I couldn't run tsc because bun couldn't write to its tempdir. The forge's check will run the type check, and the full suite, for the first time.
What changed
listBranchesinsrc/git/branches.tsnow asksgit for-each-ref --format='%(refname)%00%(ahead-behind:<default>)' refs/heads/, which needs git 2.41 or newer.- If git is older, or any output line doesn't parse, it falls back to the old
rev-listper branch. You can force that with{ bulk: false }. - A new
tipCommitsruns onegit log --no-walkfor all the tip commits. src/web/pages/branches.tsuses both, and the page reportssession,refs,compareandrenderas Server-Timing phases.test/branches-many.test.tsseeds 200 branches. It checks:- the page answers with every phase present, and under a loose 500 ms bound for the page's own time;
- the one-call counts equal the old per-branch
rev-listcounts for every branch; - the per-branch fallback gives identical rows, and the one-call path is faster.
Why the check failed before The earlier failure looked environmental. The test compared two single wall-clock timings, so one stalled run on a loaded machine could flip it. It now takes the best of three runs for each path. A comment also pointed at a call-count test that doesn't exist, and I corrected it.
What I left out
- There is no cache keyed on (branch head, base head), because the single call made it unnecessary.
- The 50 ms target isn't asserted tightly in CI, because a loaded runner would make it flaky. I haven't measured the page on a quiet machine, so I can't say it meets the 50 ms target. The call count (about two git processes instead of 200) is what should bring it down.
- The rows and their order are unchanged.
To try it, open /<owner>/<repo>/branches on the preview and read the Server-Timing header, or run bun test test/branches-many.test.ts.
The branches page now builds each row's tip line from one shared log-record parser, and the page test fails if that line breaks. bun test test/branches-many.test.ts test/branches.test.ts test/git passes (58 tests) and tsc --noEmit is clean.
- One parser:
src/git/read.tsnow exportsLOG_FORMATandparseLogRecords(bytes).commitLogandtipCommitsboth use them, so the second copy of the 7-field parser insrc/git/branches.tsis gone. - Page test:
test/branches-many.test.tsnow checks that the 200-branch page shows a tip line (· b<NN> · updated <time …> by A). I swapped two fields in the log format and two tests in that file failed. I then reverted the swap. - Already covered: a test there already compares
tipCommitswithcommitLog(…, {limit: 1})for four commits, covering body, merge parents, author, date and unsafe oids. I left it as it was. - Not done: nothing beyond what the review asked for.
The branches page now gets every branch's ahead/behind counts from one git call, not one per branch. Its tests pass here, but I couldn't run
tscbecause bun couldn't write to its tempdir. The forge's check will run the type check, and the full suite, for the first time.What changed
listBranchesinsrc/git/branches.tsnow asksgit for-each-ref --format='%(refname)%00%(ahead-behind:<default>)' refs/heads/, which needs git 2.41 or newer.rev-listper branch. You can force that with{ bulk: false }.tipCommitsruns onegit log --no-walkfor all the tip commits.src/web/pages/branches.tsuses both, and the page reportssession,refs,compareandrenderas Server-Timing phases.test/branches-many.test.tsseeds 200 branches. It checks:rev-listcounts for every branch;Why the check failed before The earlier failure looked environmental. The test compared two single wall-clock timings, so one stalled run on a loaded machine could flip it. It now takes the best of three runs for each path. A comment also pointed at a call-count test that doesn't exist, and I corrected it.
What I left out
To try it, open
/<owner>/<repo>/brancheson the preview and read theServer-Timingheader, or runbun test test/branches-many.test.ts.Closes #3376