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

Đang mở
#188 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
22/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
d3, react, typescript
Lĩnh vực
data-visualization

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
870
Fork
57
Merge trung bình
11 giờ 58 phút
Pull request đã merge (30 ngày)
18

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/charts

Tất cả issue của TanStack/charts

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.