[Perf] Focus guides: every pointer move re-renders the scene and re-serializes, re-parses and rewrites the guide layer
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 22/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- d3, react, typescript
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
focusGuideXsetsretarget: true(focus-guide.ts:336-338).resolveFocusScenethen returns a new scene object on every call (focus-layer.ts:113-115).applyStateFocusseespresented.scene !== scene(motion.ts:898-903) and runsrenderSvg+animateSvg(motion.ts:918-921), even for an unchanged focus.- Test on main: two repeated identical
paintFocuscalls cause 2renderSvgcalls.
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.
- 主要语言
- TypeScript
- 星标
- 870
- 派生
- 57
- 平均合并
- 11 小时 58 分钟
- 30 天内合并 PR
- 18
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/charts 的其他 Issue
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per node未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
[Bug] Focus guides: `url(#id)` paints ignore `idPrefix`可能已有人在做 @getdownandcode 于 37 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Add reverse options to waffleY and waffleX可能已有人在做 @tannerlinsley 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
fb55/htmlparser2#2579 ·
维护者通常 1 天内回复
-
bug good first issue needs-review
难度 1/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
documentation public
难度 1/5 1-3 小时 新手友好度 68/100
midnightntwrk/umbradb#65 ·
维护者通常 2 天内回复
-
area/channels kind/bug priority/medium
难度 2/5 1-3 小时 新手友好度 78/100
nanocoai/nanoclaw#4501 · 1 条评论 ·
维护者通常 1 天内回复
-
needs verification
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 13 天内回复