Skip to content

perf(github): cache compare API results to reduce redundant calls#15

Open
erickzhao wants to merge 1 commit into
mainfrom
cache-github-compare-results
Open

perf(github): cache compare API results to reduce redundant calls#15
erickzhao wants to merge 1 commit into
mainfrom
cache-github-compare-results

Conversation

@erickzhao

Copy link
Copy Markdown
Member

Summary

  • Adds a per-instance cache for compareCommitsWithBasehead results in GitHubVersioner, keyed on the basehead string. getMergeBase, isAncestor, getDistance, and getBranchForCommit now go through a shared getCompareResult method that deduplicates identical API calls.
  • Hoists an invariant getMergeBase(defaultBranch, sha) call out of the loop in getNearestReleaseBranchForSHA (in the base class, so both LocalVersioner and GitHubVersioner benefit).

Performance

Measured against the test fixture (erickzhao/desktop-test-fixture):

Metric Before After Change
Compare API calls 87 80 -8.0%
Total wall time 37.8s 35.5s -6.1%

Savings scale with the number of release branches. The biggest wins come from:

  • MAS build flow (getBranchForCommit called twice — second is a full cache hit)
  • Default branch path (merge-base reused when SHA matches branch point)

Test plan

  • All 30 tests pass (15 local + 15 GitHub) with no changes to test code
  • Verified API call counts with temporary instrumentation

🤖 Generated with Claude Code

The GitHub versioner's getMergeBase, isAncestor, getDistance, and
getBranchForCommit all call compareCommitsWithBasehead independently,
discarding each other's results. This adds a per-instance cache keyed
on the basehead string so identical compare pairs are only fetched once.

Also hoists an invariant getMergeBase call out of the loop in
getNearestReleaseBranchForSHA (benefits both Local and GitHub versioners).

Measured on the test fixture: 87 → 80 compare API calls (-8%), with
savings scaling proportionally to the number of release branches.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@erickzhao erickzhao requested a review from georgexu99 April 28, 2026 23:05
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.

1 participant