Skip to content

docs(perf): add picker/collect phase timings and trace instrumentation - #2250

Merged
max-sixty merged 6 commits into
mainfrom
picker-height
Apr 16, 2026
Merged

max-sixty merged 6 commits into
mainfrom
picker-height

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Expands the picker and collect module docstrings with measured phase timings, startup flow documentation, and trace instrumentation points. This makes it easier to profile startup performance and understand where time goes in both wt list and wt switch.

Changes:

  • Added "Measured Phase Timings" table to collect/mod.rs with representative medians from the dev repo
  • Expanded picker/mod.rs module docstring with startup flow sequence, phase timing table, and reproducing instructions
  • Added trace_instant calls at key picker phases (started, config resolved, layout detected, skeleton rendered)
  • Simplified trace-capture bash examples to use process substitution

This was written by Claude Code on behalf of Maximilian Roos

max-sixty and others added 6 commits April 15, 2026 13:06
Replace the worktree-only estimate with a more accurate calculation that accounts for branches when determining preview window height. The new logic short-circuits once the estimate reaches MAX_VISIBLE_ITEMS, since additional rows have no effect on the height computation. Local branches are included as a superset of worktree branches (taking the max), while remote branches are summed.
- Instrument handle_picker with six trace_instant markers covering the
  main-thread pre-collect phases (config resolution through collect
  spawn).
- Fire "Skeleton rendered" from the picker's progressive-handler path in
  collect::collect so both wt list and wt switch share a marker set.
- New wt-perf phases <list|switch> driver: runs the binary N times
  against a reproducible repo, parses [wt-trace] entries, aggregates
  per-phase median/p95/min/max durations and command counts. list runs
  pass --progressive so the skeleton instants fire under stdout redirect.
  Default --wt points at target/release/wt with a pre-flight check.
- Backfill measured phase timings into the picker and collect module
  docstrings (worktrunk dev repo, 7 worktrees, warm caches, release
  build).

Co-authored-by: Claude <[email protected]>
The previous commit added `wt-perf phases`, which mostly duplicated
infrastructure already in the repo:

- End-to-end timings: `cargo bench --bench time_to_first_output` (via
  WORKTRUNK_FIRST_OUTPUT) already covers `switch`, `list`, `remove`
  with proper criterion statistics.
- Per-phase breakdown: `wt-perf trace` emits Chrome Trace Format, and
  `benches/CLAUDE.md` documents a ready-made `trace_processor` SQL
  query that computes phase durations from instant markers.

Keep the `trace_instant` markers in `handle_picker` and the
`"Skeleton rendered"` emission from the picker's progressive-handler
path — those feed both workflows and are the actually-valuable part.
Rewrite the docstring "reproducing" sections to point at
`cargo bench time_to_first_output` and `wt-perf trace` instead of the
removed subcommand.

Co-authored-by: Claude <[email protected]>
# Conflicts:
#	src/commands/picker/mod.rs
The old examples piped stderr through grep, which was the wt-perf phases
workflow. Now that phases was dropped in favour of existing bench tooling,
simplify to process substitution with -q flag.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 16d2d6e into main Apr 16, 2026
25 checks passed
@max-sixty
max-sixty deleted the picker-height branch April 16, 2026 02:11
max-sixty added a commit that referenced this pull request May 9, 2026
## Summary

The TODO in `src/commands/picker/mod.rs` asking to "dedupe
`list_worktrees` calls between `num_items_estimate` and
`collect::collect`" has already been resolved.

`Repository::list_worktrees` has been cached on `RepoCache` since
2114fda (#2375), and the picker shares that cache across its main
thread and the bg `picker-collect` thread via `Arc<RepoCache>` —
`repo.clone()` shares the `OnceCell<Vec<WorktreeInfo>>`, so the second
call is a memory hit.

The `RepoCache::worktrees` docstring already states the contract: *"The
picker warms this on the main thread (for its preview-window sizing
estimate) so the background `collect::collect` pass hits memory instead
of respawning the subprocess on the critical path to skeleton."*

The TODO was originally added in #2250 and partially walked back in
#2368 (the parenthetical noting the branch-inventory cache), but the
body was never updated when #2375 closed the worktree half.

## Verification

`RUST_LOG=worktrunk=debug WORKTRUNK_PICKER_DRY_RUN=1 wt -C <picker-test>
switch` against the `wt-perf setup picker-test` repo shows exactly one
`git worktree list --porcelain` subprocess per invocation (1 `wt-trace`
record, 1 spawn debug line).

No behavior change — pure doc-comment deletion (9 lines).

## Test plan

- [x] `pre-commit run --files src/commands/picker/mod.rs` — passes
- [x] `cargo check` — passes
- [x] Empirical: 1 `git worktree list --porcelain` subprocess per `wt
switch`

> _This was written by Claude Code on behalf of Maximilian Roos_

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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