[Perf] Focus guides: every pointer move re-renders the scene and re-serializes, re-parses and rewrites the guide layer

Aperta
#188 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
22/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
d3, react, typescript

Direzione di ricerca

Start with the repro in packages/charts-core/test-repro/03b-crosshair-spring.test.ts and the focus path in focus-guide.ts, focus-layer.ts, motion.ts (applyStateFocus, paintFocus, and the track start around line 3990) and renderer.ts updateFocus. Done when the repro shows the crosshair x1 advancing across frames under data motion, and a repeated identical paintFocus triggers no renderSvg call. Part C (tooltip z-index and label layering) needs layout to verify, so it is not testable in jsdom.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version: @tanstack/charts 1.1.0 (57774e1).

focusGuideX, focusGuideY and crosshair follow the cursor. With motion() they are repainted on every pointer move, and each repaint costs a whole-scene render (A), a markup round-trip of the guide layer (B) and writes to guide elements that did not change (C). The cost grows with the number of guide nodes, not with what moved. Related but different: #132, #179, #178.

Impact (bklit migration, Chrome, time-x line with two series, 60 synthetic moves 17 ms apart, 8 rounds): main-thread busy time per move was a median 7.07 ms (range 6.70-8.31) with native guides, and 2.1-3.2 ms with the same guide layer drawn by our own sibling element driven from onFocusChange. Line chart hover p95 was about 25-27 ms versus about 17-18 ms for a hand-written SVG equivalent.

A. Every paintFocus re-renders the whole scene

Expected: same resolved focus gives a cheap guide paint, no whole-scene render. Fix: memoize resolveFocusScene per (scene, focus).

B. The guide layer is reparsed from markup on every focus change (from this comment)

paintMotionSvgFocusGuides renders the layer to a string with renderFocusGuideLayer (motion.ts:1209). animateSvgFragment and reconcileChartSvgFragment then parse that string through template.innerHTML (motion.ts:751-753, reconcile.ts:67-68) before diffing. Removing only the pill, or only the crosshair and dots, saved nothing measurable.

Expected: patch guide marks in place, keyed by guide, with no markup round-trip. A per-guide static flag (or skipping guides whose descriptor is unchanged) would let a guide that only moves update its transform alone.

C. Unchanged guide elements are rewritten (from this comment)

On each pointer move the reconciler sets and removes data-ts-motion-role and rewrites transform on guide elements whose target did not change (motion.ts:1164-1212, motion.ts:2247-2285).

Measured on a production build (line chart with markers, about 50 guide nodes): about 1,080 getAttribute calls and 4 set/remove pairs of the attribute per move. With a stylesheet that uses :not([data-ts-motion-role]) (the only mid-tween guard, see #196), style recalc is about 1.9 ms per move. Skipping those writes brings it to about 0.

Expected: skip the attribute and transform writes on guide elements whose target is unchanged.

Crosshair spring restarts every frame during data motion

Moved to #208 (a bug: it contradicts motion.md, and A's memo does not fix it because the scene changes every frame).

Guide labels always paint below the tooltip

Moved to #132, which asks for the same label to get a background box.

Proposed fix

One rule for A-C: the same focus and the same targets is a no-op; otherwise patch the changed guide nodes in place, without re-rendering the scene or the layer markup.

Lingua principale
TypeScript
Stelle
870
Fork
57
Merge medio
11h 58m
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/charts

Tutte le issue di TanStack/charts

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.