Skip to content

Workbench Profiler: time-window single-source-of-truth refactor (fluidity fix) #345

Closed

Description

@nockawa

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:

  1. Writes useProfilerViewStore.viewRange.
  2. selectionBridges mirrors that into useSelectionStore.time.
  3. SystemDagPanel fires two POSTs to /api/sessions/{id}/aggregate plus four heavy client-side computations (CP participation, dominant-tick CP, gating, skip rates).
  4. CriticalPathPanel recomputes the full critical-path DAG over systemTickSummaries.
  5. DataFlow / AccessMatrix already protect themselves with 150 ms debounces; useProfilerStatsWriter also 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.ts is a transitional Phase-C artefact (10-internal-data-api.md §9.2) — four Zustand-subscription mirrors between legacy per-panel stores and useSelectionStore. 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)

  1. Two-slot split in useProfilerViewStore: transientViewRange (in-flight, read only by TimeArea + future gesture-rate overlays) and viewRange (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.
  2. Delete useSelectionStore.time entirely. Every consumer (SystemDag, CriticalPath, DataFlow, AccessMatrix, SystemDagToolbar, selectionUrlSync) reads useProfilerViewStore.viewRange directly. Type unification: TimeSelection → TimeRange.
  3. Delete useSelectionStore.focusTick entirely. Redundant with viewRange. CriticalPath's display tick collapses to dominantTickInRange(viewRange) with the existing midpoint fallback for sub-tick viewports. Click handlers in TickOverview / span / phase commit viewRange to the clicked tick's bounds — the viewport visibly snaps to the clicked tick (intentional behaviour change).
  4. 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.
  5. 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 their latestTickNumber subscription.
  6. Remove redundant per-panel debounces: useProfilerStatsWriter's internal 150 ms, and the liveTime portion of useTickGatedSnapshot in DataFlow/AccessMatrix. (Keep the latestTickNumber portion — still needed for live-stream burst coalescing.)
  7. Add viewRangeDebounceMs to WorkbenchOptions (C# + TS), default 150, clamped [0, 5000].

Migration order

Nine independently-testable steps, headline fluidity check at step 4:

  1. Store changes (new slots + actions, setViewRange kept as transitional alias).
  2. TimeArea switches to setTransientViewRange + animation-end commitViewRange.
  3. useProfilerStatsWriter drops its debounce.
  4. SystemDag + CriticalPath migrate to viewRange (headline fluidity fix; instrument wheel handler to verify no synchronous spike).
  5. DataFlow + AccessMatrix drop their liveTime gate (keep latestTickNumber gate).
  6. URL sync + toolbar writers migrate to commitViewRange; delete time slot.
  7. Bridge inlining for the three remaining mirrors; delete selectionBridges.ts.
  8. Live-follow removal; one-shot first-tick init; v3→v4 persisted-state migration.
  9. 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 /aggregate is 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-panel viewRange subscribers do not fire during a transient-write burst.
  • selectionBridges.ts and its tests deleted from the codebase.
  • useSelectionStore.time and useSelectionStore.focusTick slots removed.
  • useProfilerSessionStore.liveFollowActive / setLiveFollowActive / useProfilerViewStore.liveFollowWindowUs removed; 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 through useProfilerViewStore.viewRange.
  • viewRangeDebounceMs option 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 setTransientViewRange debounce behaviour and commitViewRange atomicity.
  • 10-internal-data-api.md §9 updated to reflect post-Phase-C state (follow-up branch in the claude/ 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

Activity

  1. added
    performance
    refactoring
    on May 11, 2026
  2. moved this to Ready in Typhon devon May 11, 2026
  3. moved this from Ready to In Progress in Typhon devon May 12, 2026
  4. added a commit that references this issue on May 12, 2026
    92e69e4
  5. self-assigned this
    on May 12, 2026
  6. moved this from In Progress to Done in Typhon devon May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

performancerefactoring

Type

No type

Fields

Priority

None yet

Area

Workbench

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions