Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): PR status comes back sooner after a branch switch #28577

OpenYuruzuu(GitHub profile, opens in a new tab)wants to merge 16 commits intomain fromrefs/pull/28577/headopened View on GitHub

Yuruzuu(GitHub profile, opens in a new tab)commented

Stacked on #28575. It needs that PR's refreshAfterCheckout, and the fork can't target a PR branch upstream, so this diff shows both commits until it lands. Review only the last five commits, starting at perf(server): PR status comes back sooner after a branch switch.

Problem

After a branch switch, the PR badge took seconds to come back, even for a branch you were on moments ago. In traces from a real install, the PR lookup took 3.2–5.4 s of a 5.5–7.1 s refresh.

Change

The refresh after a checkout does work a checkout doesn't need:

  • It bumps the PR lookup epoch, which is part of the cache key, so every switch does a cold lookup. A checkout can't change a PR, so it now keeps the cache.
  • The lookup goes through the 500 ms background batch. It now uses the interactive path, since someone just picked this branch.
  • It re-reads local status after the remote read, in case a fetch moved the base for Changes totals. It now does this only if the refs moved, using the ref snapshot main added in #29155.

Explicit refreshes and turn-end refreshes behave as before. Server-only, with no contract changes, so every client gets it.

Trade-offs: a PR opened outside T3 can take up to 5 minutes to appear on a branch cached with no PR, the same limit as staying on that branch. The lookup can use reserved rate-limit quota, at one lookup per switch.

Scope and approval

71 non-test lines, all in the refresh after a checkout. There is no triaged issue. Performance work with this small a behavior trade-off may not fit the small-fix exception, so tell me if you'd rather have a discussion first.

Verification

Benchmark: real git and GitHub code in-process, in a scratch clone of this repo with origin on GitHub. 48 switches, 24 per path, alternating the order of old and new paths across 3 blocks. "Before" is the unchanged refreshStatus. "After" included #28575, which doesn't change these reads. Medians from click to PR status ready. The harness was temporary and isn't in this PR.

ScenarioBeforeAfter
Back to main6,416 ms (n=12)471 ms (n=12)
PR branch, revisit, no fetch2,367 ms (n=6)512 ms (n=3)
PR branch, first visit, no fetch2,454 ms (n=4)1,123 ms (n=3)
PR branch, first visit, fetch ran3,339 ms (n=2)3,030 ms (n=3)
Git processes per switch4833

The main row is a best case because its lookup was already cached, and a cold main lookup is still slow. A revisit where a fetch ran took 1,976 ms (n=3). The clone had a clean tree and small diffs, and samples per row are small.

Tests: new tests in VcsStatusBroadcaster.test.ts, GitManager.test.ts and GitVcsDriverCore.test.ts failed before the change and pass now. check:changed: lint, knip and tests pass (with a canonical TMPDIR on macOS). Format flags only an untracked local file. tsc --noEmit passes on apps/server, because vp run typecheck can't start in my checkout.

Not checked: this commit hasn't run in a real client. The real-client runs on the sibling PRs didn't include it. There's no new UI, only faster badge updates.

Made with Claude Opus 5.5 via Claude Code in T3 Code.

🤖 Generated with Claude Code

    1. Pushedeeca9e7

Sign in to join this conversation.