Files
orca/tools
Neil b97f524d98 perf(ai-vault): stop the session projection from stalling workspace switches
Clicking a workspace card blocked the renderer for ~1s with the AI Vault
panel open. A CPU profile put 1.7s of self time in isSessionInWorktreePath
and 1.66s in isPathInsideOrEqual.

resolveAiVaultSessionWorktreeInfo rebuilt the full candidate list inside the
per-session call, then filtered it with no early exit and sorted it. At
1124 worktrees x 500 sessions that is ~1.1M containment checks and ~2M path
normalizations per switch, all on the click path.

a1a78da878 (#10841) is what made it visible: it added an unconditional
.normalize('NFC') to normalizeRuntimePathForComparison, the innermost
function in that loop. Bisect puts the step at 344ms -> 420ms, and deleting
just that call on main reproduces the 420 -> 348 delta. The NFC fold is a
correctness fix worth keeping, so this removes the fan-out instead.

- cache the candidate list per (worktrees, repos) identity pair
- precompute each candidate's matcher via
  createNormalizedPathInsideOrEqualMatcher, so the session cwd is
  normalized once per session instead of once per candidate
- replace filter+filter+sort with a single max pass

The matcher is what #10881 added for exactly this shape; the AI Vault
fan-outs were still paying its cost without adopting it.

Projection cost on a real 1124-worktree profile: 423ms -> 13ms. Verified
byte-identical output against the previous implementation across 4501
session/worktree combinations.

Tests cover NFD/NFC matching in both directions through the projection,
the sibling-prefix boundary, nested-workspace and prior-path tie-breaks,
and a timing regression for the quadratic shape.
2026-07-28 23:23:17 -07:00
..