perf(server): cache the open-PR lookup per worktree and branch - #330
Open
Iaroslav (Rick) Postovalov (CommanderTvis) wants to merge 1 commit into
Open
Conversation
Iaroslav (Rick) Postovalov (CommanderTvis)
force-pushed
the
perf/cache-branch-review-lookup
branch
2 times, most recently
from
August 27, 2026 17:02
8f3cdda to
80e3871
Compare
Iaroslav (Rick) Postovalov (CommanderTvis)
marked this pull request as ready for review
August 27, 2026 17:04
Iaroslav (Rick) Postovalov (CommanderTvis)
force-pushed
the
perf/cache-branch-review-lookup
branch
11 times, most recently
from
August 31, 2026 16:40
927a62c to
ca281f7
Compare
Every workspace activation asked the host for the branch's open PR/MR, and so did every window focus — and the host answered by shelling out to `gh pr list`, a round trip to GitHub measured at 430-560 ms per click on this machine, in front of ~20 ms of blocking `git config`/`git remote` probes on an event loop that runs git synchronously. Clicking between two worktrees re-queried both, forever, for an answer that changes when someone opens a PR. The lookup now remembers what it last answered, per worktree and branch, and concurrent askers share one in-flight call. A `null` is cached like any other answer: "no PR" is the common case and the expensive one to re-derive. The repo-metadata nudge drops the entry for that worktree, so a PR opened or a branch switched underneath converges on the signal that already refreshes the branch label instead of waiting out the TTL. Opening a PR from the app is the one moment the cached answer stops being true without any git-metadata write to notice it, so `openPr` drops the worktree's entry on a successful outcome rather than leaving the chip reading "no PR" for the rest of the TTL. Measured on the same host and repo, switching between two worktrees: the lookup falls from ~450 ms to 0, leaving `git.status` (50-70 ms) as the largest remaining per-switch cost. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XUpDgKcBq6XUXdZc6zwvz3
Iaroslav (Rick) Postovalov (CommanderTvis)
force-pushed
the
perf/cache-branch-review-lookup
branch
from
September 1, 2026 21:40
ca281f7 to
54bbdc4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every workspace activation asked the host for the branch's open PR/MR, and so did every window focus — and the host answered by shelling out to
gh pr list, a round trip to GitHub measured at 430–560 ms per click, in front of ~20 ms of blockinggit config/git remoteprobes on an event loop that runs git synchronously. Clicking between two worktrees re-queried both, forever, for an answer that changes only when someone opens a PR.The lookup now remembers what it last answered, per worktree and branch, for 60 s, and concurrent askers share one in-flight call. A
nullis cached like any other answer: "no PR" is the common case and the expensive one to re-derive.Two things invalidate an entry rather than letting it go stale:
openPrdrops it on a successful outcome — opening a PR from the app is the one moment the cached answer stops being true without any git-metadata write to notice it, and without this the chip would keep reading "no PR" for the rest of the TTL.Measured on the same host and repo, switching between two worktrees: the lookup falls from ~450 ms to 0, leaving
git.status(50–70 ms) as the largest remaining per-switch cost.Verification
check:deps,check:seams,lint, andtypecheckpass.Unit tests: 2 fail — pre-existing and environmental (
git.test.tsforces a signing failure viagpg.program, which a machine configured withgpg.format=sshignores in favour ofgpg.ssh.program, so the commit succeeds and the assertion doesn't hold).The speedup is noticeable on my laptop.
🤖 Generated with Claude Code