Skip to content

wt select takes 15s #461

Closed
Closed

Description

@KidkArolis

Hi! When I run wt select it takes around 15 seconds for the TUI to show. It's a relatively large repo and I have ~200 branches locally.

Activity

  1. max-sixty commented on Jan 7, 2026

    @max-sixty
    Owner

    that sounds bad!

    does wt list suffer too?

  2. max-sixty commented on Jan 8, 2026

    @max-sixty
    Owner

    the new version 0.10.0 we produce a diagnostic file with wt select -vv; would you mind pasting the output of that in here?

  3. KidkArolis commented on Jan 8, 2026

    @KidkArolis
    Author

    wt list is faster and does that lazy thing where it updates on the fly - it outputs 4 items for example currently in my repo
    wt select outputs 100s (all branches and stuff?)

    I can't paste the output from those 2 commands, because it's quite sensitive. But I passed it via Claude Code for what it's worth:

    ⏺ Now I have the full picture. Here's my analysis:
    
      Summary: Why list is fast and select is slow
    
      The Numbers
      ┌───────────────────────┬────────────────────┬──────────────────────────┬───────┐
      │        Metric         │        list        │          select          │ Ratio │
      ├───────────────────────┼────────────────────┼──────────────────────────┼───────┤
      │ Output lines          │ 293                │ 5,697                    │ ~20x  │
      ├───────────────────────┼────────────────────┼──────────────────────────┼───────┤
      │ Branches processed    │ 4 (worktrees only) │ 186 (all local branches) │ ~47x  │
      ├───────────────────────┼────────────────────┼──────────────────────────┼───────┤
      │ merge-tree operations │ 16                 │ 376                      │ ~24x  │
      ├───────────────────────┼────────────────────┼──────────────────────────┼───────┤
      │ Slowest operation     │ 373ms              │ 1,824ms                  │ ~5x   │
      └───────────────────────┴────────────────────┴──────────────────────────┴───────┘
      Root Cause
    
      list only operates on existing worktrees (4 in your case).
    
      select runs git for-each-ref refs/heads/ to enumerate all 186 local branches, then computes detailed information for each branch:
    
      1. git merge-tree --write-tree origin/master <branch> - 400-1800ms each
        - Computes a hypothetical merge, requiring extensive object comparisons
      2. git rev-list --left-right --count master...<commit> - 400-600ms each
        - Counts commits divergence (some branches show 13,000+ commits behind!)
      3. git diff --name-only origin/master...<branch> - 400-600ms each
        - Lists changed files between branch and origin/master
      4. git merge-base --is-ancestor - 100-500ms each
        - Checks ancestry relationships
    
      Why Some Operations Are Especially Slow
    
      Looking at the output, branches like notify-companies-when-integration-connectedby-users-are-adv-111 show 13127↓ commits behind master. Old stale branches require traversing huge commit histories, making operations like rev-list and merge-tree extremely expensive.
    
  4. max-sixty commented on Jan 8, 2026

    @max-sixty
    Owner

    the Claude Code output is perfect, thanks!

    let me work on this...

    (iirc, skim, the library that does the fuzzy-find-panel doesn't support later updating of items. but then we should probably render less / skip ops for some branches)

  5. added a commit that references this issue on Jan 9, 2026
    bb0fde7
  6. added 3 commits that reference this issue on Jan 9, 2026
  7. max-sixty commented on Jan 10, 2026

    @max-sixty
    Owner

    @KidkArolis we now pre-check if it's likely to be expensive, and then skip the expensive checks that need to walk the tree to get the merge-base. So the next version should be much faster; lmk how you get along.

    (I haven't benchmarked the final version, but benchmarked early ones — so possible I made a mistake, would be helpful feedback if I did!)

  8. added a commit that references this issue on Jan 10, 2026
    15d3247
  9. KidkArolis commented on Jan 11, 2026

    @KidkArolis
    Author

    Thanks! Yeah, it's better, it's now 3-4 seconds for me. Which is still too long to use daily, but tbh - at this point I'll also clean up my local branches 😅

    Wondering though - why list all branches in wt select? why not just list worktrees - I only have 3 worktrees, I see them with wt list, I'd expect to see the same 3 with wt select and be able to switch easily. Maybe wt select --all could show all branches, similar to git branch -a.

  10. max-sixty commented on Jan 11, 2026

    @max-sixty
    Owner

    ok, that's still way too long. I had a quick look and it looks like there aren't many easy wins; to some extent we just had to call a lot of git commands, even after cutting the most expensive ones.

    re the branches — I think I agree with you. I originally found this useful as "what's available to work on", which included my branch list. but we could add a similar --branches flag that we currently have on wt list, and add a similar config / share it with wt list. I'll make this change.

  11. added 2 commits that reference this issue on Jan 11, 2026
  12. max-sixty commented on Jan 12, 2026

    @max-sixty
    Owner

    this is now live — wt select inherits from wt list in behavior/flags/defaults/configs.

    thanks @KidkArolis (and lmk if that doesn't help still!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions