Skip to content

[medium] perf(git-review): key the PR cache through the cached runGit - #639

Merged
sirmalloc merged 2 commits into
sirmalloc:mainfrom
elhoim:perf/git-review-ref-cache
Oct 30, 2026
Merged

sirmalloc merged 2 commits into
sirmalloc:mainfrom
elhoim:perf/git-review-ref-cache

Conversation

@elhoim

@elhoim elhoim commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

BLUF

  • Priority: medium. Removes a git subprocess that each git-pr / git-ci-status widget ran on every render.
  • getCachedGitReviewData built its cache key from git symbolic-ref --short HEAD (and rev-parse --short HEAD when detached) through a bare execFileSync, even when the PR data itself was a cache hit. The key lookup now goes through git.ts's cached runGit, which the git-branch / git-sha widgets already warm.
  • Warm render with no refresh due: 2 git spawns → 0. CPU median -3 % to -5 % and wall median -4 % to -12 % across two runs; p90 overlaps on this loaded host. stdout is byte-identical.

Details

  • GitPr and GitCiStatus now pass their render context in the options of getCachedGitReviewData.
  • With a context, the ref comes from runGit('symbolic-ref --short HEAD', context), falling back to runGit('rev-parse --short HEAD', context). Those are the same commands and the same branch: / head: / unknown key as before. runGit's persistent cache is invalidated when the HEAD or index mtime changes, so a checkout or a detached-HEAD commit still re-keys immediately.
  • Without a context (the detached refresh child and fetchGitReviewData) nothing changes.
  • The lookup is injectable (deps.runGit) so it can be tested, and falls back to the old path when absent.
  • Known, bounded window: the refresh child still derives the ref live to compute the lock path it may release. If the branch changes while runGit still serves the old cached ref (the mtime unchanged), the two sides can disagree once. The child then writes under the live ref and leaves the parent's lock in place, so refreshes for the old key pause until the lock goes stale (30 s). This is the same class of window a branch switch already has between the parent's lookup and the child's.
  • The failed-refresh respawn loop is out of scope; fix(git-review): cache confirmed absent pull requests #618 covers it.

Measurements

Spawn counts (strace, config: model + git-branch + git-pr + git-ci-status, gitCacheTtlSeconds: 0):

render before after
warm, review cache fresh 2 × symbolic-ref --short HEAD 0

Renders that happen to trigger the detached 30 s review refresh also show that child's git calls. Those are unchanged and not counted above.

bench2 (round-robin fork/exec; CPU is user+sys including reaped children; the host was heavily loaded, so compare ratios):

run arm CPU median (ms) CPU p90 wall median
40 passes, load1 28-40 / 6 cores control node -e 0 98 124 416
before 1363 1527 4622
after 1319 1524 4053
30 passes, load1 32-40 control 105 149 504
before 1443 1609 5656
after 1375 1640 5449

Checks

🤖 Generated with Claude Code

getCachedGitReviewData derived its cache key from `git symbolic-ref
--short HEAD` (and `rev-parse --short HEAD` when detached) with a bare
execFileSync, so every render spawned git once per git-pr / git-ci-status
widget even when the PR data itself was a cache hit. The widgets now pass
their render context and the ref lookup goes through git.ts's runGit, whose
persistent cache (invalidated by HEAD/index mtime) is already shared with
the git-branch and git-sha widgets. Without a context (the detached refresh
child, fetchGitReviewData) the lookup is unchanged.

Measured on a warm render with no refresh due (model, git-branch, git-pr,
git-ci-status): 2 git spawns -> 0. bench2 CPU median 1363 -> 1319 ms
(-3.3%, 40 passes) and 1443 -> 1375 ms (-4.7%, 30 passes), wall median
-12% / -4%, p90 overlapping on this heavily loaded host. stdout is
byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sirmalloc

Copy link
Copy Markdown
Owner

@elhoim Please remove branch protection for all these PRs so I can modify them if needed before squash merging to the main repo. Thanks!

@elhoim

elhoim commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

@sirmalloc Done - branch protection is removed from all 13 of my open PR branches on elhoim/ccstatusline ("Allow edits by maintainers" was already on), so you can push to them directly. Feel free to modify before squash merging. Thanks!

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@sirmalloc
sirmalloc merged commit 167652e into sirmalloc:main Oct 30, 2026
3 checks passed
@elhoim
elhoim deleted the perf/git-review-ref-cache branch October 31, 2026 22:52
sirmalloc pushed a commit that referenced this pull request Nov 5, 2026
…791)

With a tag named like the current branch, `git symbolic-ref --short HEAD`
prints "heads/<branch>". The refresh child keys the PR cache by the full
ref with "refs/heads/" stripped since #774, but the render's lookup
through the cached runGit (#639) still used --short. The two then hash
to different cache files: the child writes the PR to one, Git PR and Git
CI Status read the other, and the widgets show "(no PR)" on every render
while a refresh runs again each time its lock goes stale. The child also
never releases the lock it was handed, since that lock belongs to the
other cache file.

The render's lookup now reads `symbolic-ref HEAD` and strips the prefix
the same way, which is also the command Git Branch already runs, so the
cached runGit answers both.

Co-authored-by: effectustasi <216187407+effectustasi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants