perf(web): reduce minimap work during streaming and scrolling #9771
main fromt3code/perf-web-minimap-work·opened View on GitHubStreaming rebuilt full minimap previews for every loaded turn. Scrolling rewrote every marker's visibility attribute, even when nothing changed.
The minimap now reuses previews by immutable message identity and skips unchanged marker writes. Its cache keeps only the latest projection, so unused completed replies do not retain extra preview strings. Preview text, row indexes, geometry, and navigation stay unchanged.
Checks#
- All 241 focused tests and web typecheck passed. Lint has no new warnings.
- The Node source proof reduced a 10-turn update from 0.266 ms to 0.017 ms. A 1,000-turn stress case fell from 29.74 ms to 0.26 ms.
- Repeating unchanged geometry for 1,000 markers produced zero attribute writes instead of 100,000 across 100 scroll events.
- Parity, ref recycling, old-snapshot collection, and retained-history cache checks passed.
Small cold cases added about 0.002 ms or improved. The 1,000-turn cold stress case added 0.23 to 1.2 ms across runs. These are source measurements, not browser frame times. No browser or device run was used.
Created with GPT-6 Astra (preview) in Codex.
Note
Low Risk UI-only performance refactor in the timeline minimap with behavior-preserving tests; no auth, data, or API changes.
Overview Reduces chat timeline minimap cost during streaming and scroll by caching preview text and skipping redundant DOM updates.
Minimap item building moves from MessagesTimeline.tsx into createTimelineMinimapProjector: a stable projector caches compact user/assistant preview strings keyed by ChatMessage object identity, evicts previews not in the latest projection, and still updates rowIndex when rows reorder. Scroll handling delegates to updateTimelineMinimapMarkers, which sets each strip’s data-in-view only when visibility actually changes (including remounted/recycled refs).
The component keeps one projector instance via useState(createTimelineMinimapProjector) instead of recomputing all previews on every row change. New unit tests cover marker write counts, ref recycling, cache reuse, and parity when turns reorder or supersede earlier replies.
Note
Cache minimap previews and skip redundant marker writes in MessagesTimeline#
- Extracts minimap projection and marker-update logic from MessagesTimeline.tsx into MessagesTimeline.logic.ts
createTimelineMinimapProjectorcaches preview strings byChatMessageobject identity for only the latest projection, scans rows backward to pair each user row with its first assistant row, and returns null for blank previewsupdateTimelineMinimapMarkersresolves the visible interval from scroll state, computes row intersections using finite row positions, and writes dataset only when the marker's visible state actually changes- Risk:
resolveTimelineRowTopandresolveTimelineRowHeightreturn false when row positions are non-finite; marker visibility falls back to false in that case
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
1e9eca8Macroscope's review found this PR approvable — This is a localized, behavior-preserving minimap performance refactor that caches immutable previews and avoids redundant marker DOM writes. Focused tests cover streaming updates, row reordering, cache eviction, and recycled references, with no API, schema, security, billing, or deployment changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Superseded by #11181 (W15): minimap previews are now formatted only when opened, so unbounded preview construction during streaming is no longer needed.
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
8e056a0· PR result:1e9eca8· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.