Repository navigation
perf(picker): cache log/branch-diff/upstream-diff renders to disk - #2628
Merged
Merged
Conversation
The picker pre-computes four previews per item at skeleton time. Three of
them — Log, BranchDiff, UpstreamDiff — are pure functions of git object
SHAs at a given terminal width, so rendering them on every `wt switch`
duplicates work that the prior invocation already did. Add a SHA-keyed
disk cache alongside the existing `sha_cache` so warm-cache invocations
short-circuit the git subprocess.
Layout: `.git/wt/cache/picker-preview/{mode}-{sha}[-{sha}]-{w}[-{h}].json`.
Cached values are pre-pager strings, so changing the configured pager
invalidates nothing; the pager step in `compute_and_page_preview` runs on
every read. Default-branch and upstream SHAs are resolved via `rev-parse`
inside the BranchDiff and UpstreamDiff compute paths so the cache key
stays stable across `git fetch`. WorkingTree mode is not cached — its
inputs include the mutable working tree, which has no cheap stable hash.
Summary mode already has its own cache.
LRU bound is 500 entries (rendered diffs are tens of KB, much larger
than the 80-byte SHA-pair entries `sha_cache` is sized for).
Bundled into the existing `git commands cache` user-facing category in
`wt config state get` and `state clear --all` — both `sha_cache` and the
new picker preview cache surface as one count and clear together. The
implementation stays in `commands/picker/preview_cache.rs` (picker-owned,
distinct LRU bound) rather than mixing into `git/repository/sha_cache.rs`.
Tests: round-trip + width/SHA invalidation in the new module, plus
short-circuit and write-back tests through each `compute_*_preview`
covering pre-populated cache hits and post-miss writeback.
Co-Authored-By: Claude <[email protected]>
`commands::picker` is `#[cfg(unix)]` so its preview cache module doesn't exist on Windows. The bundled "git commands cache" reporting in state.rs referenced the picker cache directly, breaking the Windows build. Add two cfg-conditional shim functions (`picker_preview_count`, `picker_preview_clear`) that forward to the picker cache on unix and return 0 / Ok(0) elsewhere. Call sites in `handle_state_show_json`, `handle_state_show_table`, and `handle_state_clear_all` use the shims so the JSON/table shape and clear messaging stay platform-agnostic. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
The branch-diff and upstream-diff caches look right — both keys cover every input that feeds the rendered output. One concern on the log cache: see inline comment.
Per worktrunk-bot's review on PR #2628: the log preview cache value was the final rendered string, but `compute_log_preview_uncached` reads two inputs that aren't in the cache key: - `merge-base(default_branch, head)` drives the dim/bright commit split. When `main` advances to contain feature's commits, merge-base moves and `unique_commits` empties — every commit should render dimmed. A cached entry kept the pre-advance bright styling until LRU eviction. - `format_log_output` calls `format_relative_time_short(epoch_now())` on the `width >= 50` path, so cached "5m" / "2h" / "3d" strings drift with wall-clock. With no TTL, a cached "5m" could read "5m" days later. Split the cached payload into a `LogCacheEntry { raw_log, stats }` — just the SHA-deterministic outputs of `git log --graph` and `batch_fetch_stats`. The render path runs `merge-base` + `rev-list` for fresh `unique_commits`, then `process_log_with_dimming` and `format_log_output` against `epoch_now()`. Cache key stays `(branch_head_sha, w, h)` — keeping `main`'s SHA out means a `git fetch` that advances `origin/main` doesn't invalidate every entry; branches are stable far more often than main, so hit rate is higher across long time windows. Net hit savings: skips `git log --graph` + `batch_fetch_stats` (~20–100 ms), pays the merge-base + rev-list refresh (~10–20 ms). Tests: - `log_cache_writeback_on_miss`: cache is populated after first compute; different width still misses. - `log_cache_dim_split_tracks_main_advance`: regression for the original reviewer concern. Feature branches off main with a unique commit, then main fast-forwards to include it. Same `branch_head_sha` (cache hit), but the dim/bright split must update — asserted via the bold-green branch decoration `\x1b[1;32m`, which `process_log_with_dimming`'s dim path strips from the cached raw log. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
May 7, 2026
max-sixty
added a commit
that referenced
this pull request
May 10, 2026
Bump worktrunk to **0.49.0** — minor bump (semver-checks reports a
breaking change in `GitError::UncommittedChanges`, which gained a
`dirty_files: Vec<String>` field).
## Highlights
**Improved**
- New `codename(n)` template filter — deterministic friendly worktree
names from a ~1.26M-combo pool (`{{ branch | codename(2) }}` →
`malleable-opah`).
[#2641](#2641), thanks
@endigma
- Picker preview disk cache for Log / BranchDiff / UpstreamDiff, with
background refresh for stale Log decorations.
[#2628](#2628),
[#2646](#2646)
- Picker shares one `default_branch_sha` lookup across BranchDiff items
instead of forking N rev-parse subprocesses.
[#2658](#2658)
- "X has uncommitted changes" errors now list the dirty files inline.
[#2653](#2653)
**Fixed**
- `wt switch` integrates with `cd` aliases like zoxide (uses `builtin
cd`). [#2644](#2644), thanks
@xkumiyu for reporting
- Empty hook tables no longer panic during `wt switch --create`.
[#2635](#2635), thanks @topit
for reporting
- `Repository::current_worktree()` and five sibling helpers no longer
silently leak the process CWD when called via `Repository::at(p)`.
[#2652](#2652)
- `WorkingTree::is_linked` tolerates non-git CWDs (e.g. Nix sandbox).
[#2625](#2625), thanks
@DArtagan for reporting
- Picker no longer overlays `collect` warnings on the active TUI; clears
its frame on exit in inline mode.
[#2627](#2627),
[#2626](#2626)
- Failed `git log` no longer poisons the picker's preview disk cache.
[#2651](#2651)
- `wt step prune` says "removing branch" for branch-only candidates.
[#2619](#2619)
- Claude Code Windows integration uses a `wt.sh` wrapper to avoid
colliding with Windows Terminal's `wt.exe`.
[#1754](#1754), thanks
@lucaspimentel
**Documentation**
- cmux workspace integration recipe.
[#1907](#1907), thanks
@alvistar
See
[CHANGELOG.md](https://github.com/max-sixty/worktrunk/blob/release/CHANGELOG.md)
for the full list including internal CI / test-isolation changes.
## Test plan
- [x] `cargo run -- hook pre-merge --yes` (tests + lints clean)
- [x] `cargo semver-checks check-release -p worktrunk` (one breaking
change confirmed → minor bump)
- [x] CHANGELOG entries verified by subagent against actual diffs
🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
The picker pre-computes four previews per item at skeleton time. Three of them — Log, BranchDiff, UpstreamDiff — are derivable from git object SHAs at a given terminal width, so rendering them on every `wt switch` duplicates work the prior invocation already did. This adds a SHA-keyed disk cache alongside the existing `sha_cache` so warm-cache invocations short-circuit the git subprocesses.
What's cached, by mode
(base_sha, head_sha, width)— cache value is what the existingcompute_*_previewreturns. Default-branch and upstream SHAs are resolved viarev-parseso the key stays stable acrossgit fetch.git log --graphoutput + per-commit(insertions, deletions)map). The render path recomputesmerge-base+rev-listfor the dim/bright split and runsformat_log_outputagainstepoch_now()on every call. Why split: dim/bright shifts asmainadvances, and relative-time strings drift with wall-clock — neither is in the SHA-deterministic part. Caching just the raw log + stats means the cache key stays(branch_head_sha, w, h)(nomaindimension, no time bucket) while output stays correct.Layout:
.git/wt/cache/picker-preview/{mode}-{sha}[-{sha}]-{w}[-{h}].json. Diff modes cache pre-pager strings (the pager step incompute_and_page_previewruns on every read, so changing the configured pager invalidates nothing). LRU bound is 500 entries — rendered diffs are tens of KB each, vs the 80-byte SHA-pair entriessha_cacheis sized for at 5000.State management
Bundled into the existing "git commands cache" user-facing category in `wt config state get` and `state clear --all` — both `sha_cache` and the new picker preview cache surface as one count and clear together. Implementation stays in `commands/picker/preview_cache.rs` (picker-owned, distinct LRU bound) rather than mixing into `git/repository/sha_cache.rs`. Because the picker module is
#[cfg(unix)], two cfg-conditional shims instate.rskeep the JSON/table shape platform-agnostic on Windows.Key files
Tests
Round-trip + width/SHA invalidation in the new module, plus per-mode short-circuit / writeback tests through each `compute_*_preview`. Includes a regression test for worktrunk-bot's review feedback (`log_cache_dim_split_tracks_main_advance`): branches feature off main, advances main to include feature's commit, asserts the cached log re-dims via the stripped bold-green branch decoration.