[Perf] `motion()`: every update resolves each element's timing context with DOM queries and scans of all points
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Refactoring
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- d3, javascript, typescript
- Bereich
- data-visualization, performance
Rechercherichtung
Start in packages/charts-core/src/motion.ts, especially addUpdateTrack, createPresentationTracks, elementTimingContext, and motionPointForKey; compare the current scene walk with the proposal to build a key-to-point map and per-mark point counts once. Trace how the reconcile walk can supply each leaf's group, role, and peers, then run the motion tests and benchmark the supplied motion() repro against static SVG. Done when repeated per-element DOM queries and full-scene scans are removed and update cost scales closer to element count.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Version: @tanstack/charts 1.5.0 (b236dae).
Under motion(), an update's cost grows faster than its element count. One keyed rect mark, only y values changing, median synchronous host.update in headless Chromium 153:
| Bars | motion() |
Static SVG renderer |
|---|---|---|
| 100 | 3.5 ms | 0.9 ms |
| 200 | 7.6 ms | 1.3 ms |
| 400 | 19.4 ms | 2.1 ms |
| 800 | 60.7 ms | 4.0 ms |
Compiling the scene is about 1 ms at 800 bars. A CPU profile at 400 bars puts 68% of host.update inside elementTimingContext, 26% in motionPointForKey alone.
Why
addUpdateTrack resolves a timing context for every retained element (motion.ts:2198), and createPresentationTracks again for every point that moved (motion.ts:3368-3371). Each one starts from the leaf:
- nine
closest()calls for onerect(motion.ts:2918-3074); motionPointForKeywalks every point of the scene and builds a string for each (motion.ts:3220-3236), then the points are filtered bymarkIdonly to count them (motion.ts:3093-3097);- a tick collects and filters every keyed element of its axes group to count its peers (motion.ts:3051-3056).
A mark with n elements does about n² string comparisons for each update.
Repro
Bundle for a browser and run await bench().
import { defineChart, rect } from '@tanstack/charts'
import { motion } from '@tanstack/charts/motion'
import { mountChartRenderer } from '@tanstack/charts/renderer'
import { scaleLinear } from '@tanstack/charts/scales/linear'
import { createSvgChartRenderer } from '@tanstack/charts/svg/renderer'
const definition = (count: number, step: number) =>
defineChart({
marks: [
rect(
Array.from({ length: count }, (_, k) => ({ key: `r${k}`, x1: k - 0.4, x2: k + 0.4, y2: 40 + 30 * Math.sin(step + k) })),
{ x1: 'x1', x2: 'x2', y1: () => 0, y2: 'y2', key: 'key' },
),
],
scales: { x: { scale: scaleLinear().domain([-0.5, count - 0.5]) }, y: { scale: scaleLinear().domain([0, 80]) } },
pointer: false,
})
async function measure(count: number, animated: boolean) {
const renderer = animated ? motion({ initial: false }) : createSvgChartRenderer()
const options = (step: number) => ({ definition: definition(count, step), renderer, width: 900, height: 300, ariaLabel: 'cost' })
const host = mountChartRenderer(document.body.appendChild(document.createElement('div')), options(0))
const times: number[] = []
for (let step = 1; step <= 60; step++) {
await new Promise(requestAnimationFrame)
const next = options(step)
const started = performance.now()
host.update(next)
times.push(performance.now() - started)
}
host.destroy()
return times.sort((a, b) => a - b)[30]?.toFixed(1)
}
window.bench = async () => {
await measure(100, true) // warm up
for (const count of [100, 200, 400, 800])
console.log(`${count} bars: motion() ${await measure(count, true)} ms, static SVG ${await measure(count, false)} ms`)
}
Proposal
Build a key-to-point map and a point count for each markId once for a scene, and find the owning group, role and peers on the way down the reconcile walk, not from each leaf.
Related: #186, #188, #201, PR #268.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 870
- Forks
- 57
- Ø Merge
- 11 Std. 58 Min.
- Gemergte PRs (30 T.)
- 18
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/charts
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per nodeOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug] Focus guides: `url(#id)` paints ignore `idPrefix`Evtl. vergeben @getdownandcode hat das vor 37 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
TanStack/charts#211 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add reverse options to waffleY and waffleXEvtl. vergeben @tannerlinsley hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 25/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in TanStack/charts
Ähnliche Issues
-
inference/go type/feature
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 72/100
anomalyco/opencode#65148 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
truapi-release
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
paritytech/product-sdk#529 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add: Mansudae TVOffenapproved check:passed streams:add
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
devlikeapro/waha#2369 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
bigbluebutton/bigbluebutton#26638 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag