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

未关闭
#188 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 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

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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/charts 的其他 Issue

查看 TanStack/charts 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。