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

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

opened this

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.

Notes

opened this

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

  • listBranches in src/git/branches.ts now asks git 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-list per branch. You can force that with { bulk: false }.
  • A new tipCommits runs one git log --no-walk for all the tip commits.
  • src/web/pages/branches.ts uses both, and the page reports session, refs, compare and render as Server-Timing phases.
  • test/branches-many.test.ts seeds 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-list counts 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.

Closes #3376

2 earlier comments
commented

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

  • listBranches in src/git/branches.ts now asks git 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-list per branch. You can force that with { bulk: false }.
  • A new tipCommits runs one git log --no-walk for all the tip commits.
  • src/web/pages/branches.ts uses both, and the page reports session, refs, compare and render as Server-Timing phases.
  • test/branches-many.test.ts seeds 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-list counts 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.

commented

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.ts now exports LOG_FORMAT and parseLogRecords(bytes). commitLog and tipCommits both use them, so the second copy of the 7-field parser in src/git/branches.ts is gone.
  • Page test: test/branches-many.test.ts now 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 tipCommits with commitLog(…, {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.
commented

Steward: closing as a duplicate of #5666 (same change, same title). #5666 is approved and green on a fresh head, so the work lands there.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs