Skip to content

perf(nav-panel): optimize workspace session hierarchy indexing and partitioning - #3800

Open
Raing5Days wants to merge 1 commit into
GCWing:mainfrom
Raing5Days:perf/nav-tree-virtual
Open

Raing5Days wants to merge 1 commit into
GCWing:mainfrom
Raing5Days:perf/nav-tree-virtual

Conversation

@Raing5Days

Copy link
Copy Markdown
Contributor

## Summary

Optimize sidebar multi-workspace session hierarchy indexing and partitioning in getWorkspaceSessionHierarchy (sessionNavHierarchy.ts), eliminating $O(N \times M)$ linear scans, intermediate array copies, and redundant relationship normalization for normal sessions.

  • Replace the linear workspaceIds.some(...) search with a pre-indexed workspaceIdSet ($O(1)$ lookup) and resolve sessionOwningWorkspaceId only once per session candidate instead of per workspace ID.
  • Avoid multiple intermediate .filter() and new Set(scoped.map(...)) passes by collecting candidate sessions and knownIds in a single forward loop.
  • Introduce resolveParentSessionId: fast-paths the vast majority of ordinary top-level normal sessions (where sessionKind === 'normal' without parent pointers) directly to undefined, avoiding full resolveSessionRelationship and normalizeSessionRelationship heap object allocations.
  • Partition parent and child hierarchies in a single indexing pass.

Type and Areas

Performance / refactoring. Web UI sidebar navigation (src/web-ui/src/app/components/NavPanel/sections/sessions/sessionNavHierarchy.ts). No wire protocol, persisted schema, or UI contract changes.

Motivation / Impact

In workspaces with extensive history (e.g. hundreds of sessions spanning multiple project roots):

  • Every sidebar revision (session activity updates, ordering refreshes, or workspace switching) repeatedly ran Array.from(sessions).filter(...) and re-scanned workspaceIds linearly.
  • For 600+ sessions, this caused repeated 3–4 ms synchronous main-thread spikes during sidebar navigation.

With single-pass set lookup and relationship fast-pathing:

  • P95 Indexing Latency: dropped from 3.72 ms to 0.68 ms (an ~80% latency reduction, well within the 1.0 ms budget).
  • Peak Single Frame Latency: reduced from 3.72 ms to 1.46 ms (budget ≤ 2.5 ms).
  • Garbage Collection: eliminated intermediate array allocations per hierarchy pass.

Verification

  • node scripts/run-vitest.mjs run --maxWorkers=50% "src/app/components/NavPanel/sections/sessions/sessionNavHierarchy.test.ts" — 4 passed (100%), covering 659-record multi-workspace hierarchy counts.
  • node scripts/check-repo-hygiene.mjs — passed.
  • node --test scripts/check-repo-hygiene.test.mjs — 3 passed (100%).
  • node scripts/verify-release-version-sync.mjs — passed.
  • node scripts/format-changed-rust.mjs — passed.
  • git diff --check — clean.

Checklist

  • Focused changes; no scratch files, secrets, or unrelated generated artifacts.
  • Relevant verification and test results are recorded above.
  • Preserves exact parent-child hierarchy, workspace ownership, and transient/subagent filter contracts.

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.

1 participant