Repository navigation
Description
Summary
Refactor the Workbench profiler's time-window architecture to eliminate the synchronous pan/zoom fan-out that causes UI judder, collapse two redundant stores into one canonical source of truth, delete the selectionBridges indirection, simplify live mode, and remove three now-redundant per-panel debounces.
Design doc: claude/design/Apps/Workbench/profiler-time-window-refactor.md — full architectural detail, migration order, and feasibility audit findings.
Problem
Every wheel notch / drag pixel / rAF zoom-animation frame in TimeArea synchronously:
- Writes
useProfilerViewStore.viewRange. selectionBridgesmirrors that intouseSelectionStore.time.SystemDagPanelfires two POSTs to/api/sessions/{id}/aggregateplus four heavy client-side computations (CP participation, dominant-tick CP, gating, skip rates).CriticalPathPanelrecomputes the full critical-path DAG oversystemTickSummaries.DataFlow/AccessMatrixalready protect themselves with 150 ms debounces;useProfilerStatsWriteralso debounces internally — three duplicate timers solving the same problem in different places.
Net effect: panning the timeline jitters, and the user can't reliably scrub because every gesture frame is contested by an aggregate fetch + CP recomputation.
Additionally:
- Live-follow mode (attach) auto-snaps the viewport on every engine tick, making the timeline impossible to interact with. The feature actively prevents the inspection it should enable.
selectionBridges.tsis a transitional Phase-C artefact (10-internal-data-api.md §9.2) — four Zustand-subscription mirrors between legacy per-panel stores anduseSelectionStore. Completing the migration deletes the file.- The 150 ms debounce window is hard-coded in three places, with no user knob.
Proposed solution (high-level)
- Two-slot split in
useProfilerViewStore:transientViewRange(in-flight, read only by TimeArea + future gesture-rate overlays) andviewRange(committed, debounced, read by every cross-panel consumer). Pan/drag/wheel/rAF writes transient; debounced commit copies into viewRange. Animation-end and programmatic writes commit both atomically. - Delete
useSelectionStore.timeentirely. Every consumer (SystemDag, CriticalPath, DataFlow, AccessMatrix, SystemDagToolbar, selectionUrlSync) readsuseProfilerViewStore.viewRangedirectly. Type unification:TimeSelection→TimeRange. - Delete
useSelectionStore.focusTickentirely. Redundant withviewRange. CriticalPath's display tick collapses todominantTickInRange(viewRange)with the existing midpoint fallback for sub-tick viewports. Click handlers in TickOverview / span / phase commitviewRangeto the clicked tick's bounds — the viewport visibly snaps to the clicked tick (intentional behaviour change). - Delete
selectionBridges.ts. The three remaining cross-store mirrors (selectedResource→resource, schemaInspector↔component) inline into store setter actions. No Zustand subscriptions in the cross-store layer. - Delete live-follow mode. On attach, one-shot first-tick init sets
viewRange = [firstTick.startUs, firstTick.endUs]. After that the viewport never moves automatically; TickOverview and OverloadStrip still paint the growing trace extent via theirlatestTickNumbersubscription. - Remove redundant per-panel debounces:
useProfilerStatsWriter's internal 150 ms, and theliveTimeportion ofuseTickGatedSnapshotin DataFlow/AccessMatrix. (Keep thelatestTickNumberportion — still needed for live-stream burst coalescing.) - Add
viewRangeDebounceMstoWorkbenchOptions(C# + TS), default 150, clamped[0, 5000].
Migration order
Nine independently-testable steps, headline fluidity check at step 4:
- Store changes (new slots + actions,
setViewRangekept as transitional alias). - TimeArea switches to
setTransientViewRange+ animation-endcommitViewRange. useProfilerStatsWriterdrops its debounce.- SystemDag + CriticalPath migrate to
viewRange(headline fluidity fix; instrument wheel handler to verify no synchronous spike). - DataFlow + AccessMatrix drop their
liveTimegate (keeplatestTickNumbergate). - URL sync + toolbar writers migrate to
commitViewRange; deletetimeslot. - Bridge inlining for the three remaining mirrors; delete
selectionBridges.ts. - Live-follow removal; one-shot first-tick init; v3→v4 persisted-state migration.
- Options plumbing (server + client + UI control).
Acceptance criteria
- Pan/zoom in the TimeArea remains 60 Hz fluid with SystemDag, CriticalPath, DataFlow, and AccessMatrix all open and visible. Verified via a Playwright spec that asserts
/aggregateis decoupled from gesture-frame count (e2e/profiler-aggregate-debounce.spec.ts, follow-up branch). Plus a vitest subscription-fire test (useProfilerViewStore.transient.test.ts) proving cross-panelviewRangesubscribers do not fire during a transient-write burst. -
selectionBridges.tsand its tests deleted from the codebase. -
useSelectionStore.timeanduseSelectionStore.focusTickslots removed. -
useProfilerSessionStore.liveFollowActive/setLiveFollowActive/useProfilerViewStore.liveFollowWindowUsremoved; toolbar toggle UI gone. - First tick in attach mode pins viewport to that tick; subsequent ticks do not move the viewport.
-
?time=...URL deep-links continue to work, round-tripping throughuseProfilerViewStore.viewRange. -
viewRangeDebounceMsoption visible in the Workbench options dialog under Profiler; default 150; tested at 0 (sync) and at a high value (300+) to confirm the knob works. - All existing tests pass; 6 test files updated per the design doc §J; new tests added for
setTransientViewRangedebounce behaviour andcommitViewRangeatomicity. -
10-internal-data-api.md §9updated to reflect post-Phase-C state (follow-up branch in theclaude/docs repo).
Landed via PR #346 (main refactor) and follow-up branch feature/345-followup (Playwright e2e spec + subscription-fire vitest + post-review hardening: tightened ChunksPerWorker validation bounds, stronger oversubscription tests including tier-filtered path).
Behaviour changes to surface in the PR description / changelog
- Clicking a tick in TickOverview (or a span / phase in TimeArea) now also moves the viewport to that tick's bounds, where today it only updates the selection / CP overlay. Intentional simplification — one concept, one slot.
- Live-follow mode is gone. Attach sessions pin to the first tick on arrival and stay there until the user pans/zooms.
Risks / open questions
- Initial window width in attach mode: spec'd as 1-tick-wide; revisit if it feels too narrow in practice.
- OverloadStrip's exact subscription pattern wasn't fully verified in the audit — confirm at step 2.
- Niche use case lost: "pin tick X while panning a wider window." Workaround is "zoom in to pin." Acceptable trade for the simplification.
Labels
workbench, performance, refactoring
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Area
Activity
Workbench Profiler: time-window single-source-of-truth refactor + Chu…
Follow-up: Playwright e2e + post-review hardening on ChunksPerWorker #…