Repository navigation
perf(list): skip the PR/MR lookup for branches never pushed - #4289
Merged
Merged
Conversation
A forge opens a PR/MR only from a branch it hosts, so a local branch that no remote has under its name can't head one. `wt list --full` still asked the forge about every such branch: on a repo with 239 local branches, of which 19 exist on `origin`, that was 239 `gh pr list` calls at ~450ms and ~65ms of CPU each, about 15 CPU-seconds whenever the CI cache had expired. `detect_ci` now skips the PR/MR lookup for a local branch unless some remote has that name, or the branch pushes to a URL (`gh pr checkout` of a fork's PR sets that, and git keeps no `refs/remotes/` copy of a URL remote). Both checks read inventories already cached for the command. The branch-workflow fallback is unchanged. The push remote now comes from the local-branch scan (`%(push:remotename)`) instead of one `for-each-ref` per branch, so `push_remote_url` forks nothing after the first scan and the per-branch cache it needed is gone. On that repo, with the CI cache cleared: 249 forge calls become 25. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
In single-branch and shallow clones, a pushed branch now never shows its PR. The details are inline.
A missing `refs/remotes/<remote>/<branch>` shows a branch was never pushed only where a push would have recorded one. `git push` updates the remote-tracking ref only where the remote's fetch refspecs map the branch, so in a `--single-branch` or `--depth` clone, which maps only the cloned branch, a pushed branch with an open PR looked unpushed and lost its CI. The skip now also requires the push remote (or the primary remote, when none is set) to have a fetch refspec mapping the branch into `refs/remotes/`. A URL push remote has no refspecs, so that case falls out of the same rule and `Branch::pushes_to_url` goes away. The blank-CI help row now says "never pushed". Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Sep 27, 2026
max-sixty
pushed a commit
that referenced
this pull request
Sep 27, 2026
Four comments no longer matched the code after yesterday's `wt list` perf work. This PR changes only comments, no behavior. - **`src/commands/list/collect/mod.rs`**: the stale-default-branch note said the picker skips the local branch inventory (#5) when branches are hidden, so it can fork one `for-each-ref`. Since #4290, the first scan phase primes `repo.local_branches()` unconditionally. The check reads the cached inventory, so it never forks. - **`src/commands/list/ci_status/mod.rs`**: `detect_uncached` said "PR/MR detection always runs". Since #4289, `platform::detect_ci` skips the lookup for a branch that was never pushed (`may_head_pr`). - **`tests/integration_tests/push.rs`**: a test doc named `finalize_worktree`, which #4286 renamed to `finalize_worktrees`. - **`src/shell_exec.rs`**: `Cmd::run_concurrently` said at most `max_concurrent_commands()` children run at once. A background batch takes a single semaphore permit while other threads hold the rest, so the cap holds per batch, not per process. The comment now says so. No test accompanies this, since only comments change. Co-authored-by: worktrunk-bot <[email protected]>
1 task
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.
A forge opens a PR/MR only from a branch it hosts, so a local branch that no remote has under its name can't head one.
wt list --full, the statusline and the picker still asked the forge about every such branch whenever the CI cache (30–60s) had expired. On a repo with 239 local branches, of which 19 exist onorigin, that was 249ghcalls at ~450ms and ~65ms of CPU each, about 15 CPU-seconds per run.detect_cinow skips the PR/MR lookup for a local branch that was never pushed: no remote has a branch by that name, and the branch's push remote (or the primary remote, when none is set) has a fetch refspec that would have recorded it underrefs/remotes/.git pushupdates the remote-tracking ref only where the fetch refspecs map the branch. So a--single-branchor--depthclone, which maps only the cloned branch, still asks the forge about every other branch. A URL push remote (gh pr checkoutof a fork's PR) has no refspecs and is still asked about too. Both checks read the ref inventory and config map already cached for the command. The branch-workflow fallback is unchanged, and the rule applies to every forge.The push remote now comes from the existing local-branch scan (
%(push:remotename), no measurable cost) instead of onefor-each-refper branch.Branch::push_remote_urlforks nothing after the first scan, and the per-branch cache that existed only to avoid that fork is deleted.Measured with
wt list --fullon that repo, CI cache cleared, 5 runs each at load average ~30:ghcallsUnder that load the local git work was the bottleneck, and the 25 calls started only at 2.3–5s. On a quiet machine the CI tail should be close to one round trip; that's an estimate, not a measurement.
The trade-off: a PR opened from a branch pushed by another clone, and not yet fetched here, shows no PR until the next fetch. The help text's blank-CI row now reads "Branch never pushed", replacing "No upstream", which was never exactly when the cell goes blank.
test_pr_lookup_skips_branches_on_no_remotechecks theghcall log for four cases: pushed, URL push remote, a push remote set up like a--single-branchclone, and never pushed. Dropping either the remote check or the refspec check fails it.refspecs_track_ref_follows_the_fetch_mappingcovers the refspec matching, including negative refspecs.🤖 Generated with Claude Code