You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: build mixed Canvas and SVG layers in linear time - #276
Mixed Canvas/SVG charts can spend quadratic time building their layers. This appends each node once while preserving renderer order and nested group metadata. Thanks @le-marais for the report and reproduction.
AI review notes:
The layer builder owns its arrays, so appending a node does not mutate the input scene. The helper now takes one node directly, avoiding both repeated array copies and temporary layer objects.
Independently verified: 137 Canvas/renderer tests, type checking, the explicit bundle policy gate, and the complete packed-package gate including Native/Expo, seven framework adapters and the unified artifact. No dependencies, exported APIs, workflows, budgets or fingerprint locks changed.
A deterministic traversal regression fails on current main with 265,214 node visits for 512 points and passes with this change. Frozen-input, nested-group and renderer-boundary checks also pass.
In a Node 24/jsdom fixture using the public layered prerender entry point with paint methods stubbed, seven-sample medians at 32,000 points were 879.83 ms before and 0.30 ms after. These are composition timings, not browser frames. The baseline fixture completed its samples but exceeded Vitest's five-second test timeout.
All four affected measured Canvas consumers became smaller. Required CI, current-head review and any source fingerprint gate remain to be completed before merge. The issue stays open until delivery is verified.
Summary by CodeRabbit
Performance
Improved composition of mixed Canvas and SVG layers, avoiding repeated copying of collected nodes.
Tests
Added coverage for layer ordering, custom-renderer routing, nested groups, and preservation of input data.
No actionable comments were generated in the recent review.
Walkthrough
splitRenderLayers now appends nodes to mutable arrays instead of repeatedly merging node arrays. Tests cover node visits, renderer ordering, and nested groups. Renderer selection and custom-renderer tracking remain unchanged.
Changes: Canvas layer composition
Layer / File(s)
Summary
Compose and validate render layers packages/charts-core/src/canvas.ts, packages/charts-core/src/canvas-layers.test.ts, .changeset/fast-canvas-layer-composition.md
splitRenderLayers appends nodes to matching renderer layers. Tests check node visits, SVG and canvas ordering, and nested group behavior. The changeset declares a patch release for @tanstack/charts.
Change: Refactor · Severity of issue fixed: Medium
Merge Risk: Minimal · up to 47de3
This change makes mixed Canvas and SVG layer composition linear while preserving renderer order and group metadata. No actionable merge-blocking risk was found. Confirm that CI passes before merging.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title states the main change: mixed Canvas and SVG layer construction is changed from quadratic to linear time, which matches the linked issue #275 and the canvas.ts change that appends nodes to t…
Linked Issues check
Directly linked issue #275 asks that splitRenderLayers in packages/charts-core/src/canvas.ts compose layers in linear time without re-copying the node array per node, while preserving renderer groupin…
Out of Scope Changes check
The PR touches three files: a patch changeset for @tanstack/charts describing linear-time Canvas/SVG layer composition, packages/charts-core/src/canvas-layers.test.ts (regression and behavior tests fo…
Full details: Title check
Explanation
The title states the main change: mixed Canvas and SVG layer construction is changed from quadratic to linear time, which matches the linked issue #275 and the canvas.ts change that appends nodes to the current layer instead of copying arrays. The 'perf:' prefix is a conventional type label and does not reduce clarity. The title is specific and does not mention unrelated work.
Full details: Linked Issues check
Explanation
Directly linked issue #275 asks that splitRenderLayers in packages/charts-core/src/canvas.ts compose layers in linear time without re-copying the node array per node, while preserving renderer grouping, order, and recursion into groups. The PR summary and the AI-generated change summary state that splitRenderLayers now builds mutable layer node arrays and appends each node to the latest layer when the renderer matches, keeping custom-renderer resolution, group splitting, and the hasCustomRenderer flag. The new canvas-layers.test.ts adds a deterministic bounded-iterator-visit test for 512 consecutive nodes and a focus group, plus SVG ordering, custom-renderer routing, and nested-group preservation tests. Limitation: the diff read for canvas.ts was unavailable and the file view was truncated before splitRenderLayers, so the code-level behavior rests on the summaries and the reported test evidence, not on a direct read of the changed lines. The reported timing data (879.83 ms to 0.30 ms at 32,000 points) is composition evidence supplied by the author, not verified here.
Full details: Out of Scope Changes check
Explanation
The PR touches three files: a patch changeset for @tanstack/charts describing linear-time Canvas/SVG layer composition, packages/charts-core/src/canvas-layers.test.ts (regression and behavior tests for the same function), and packages/charts-core/src/canvas.ts (the splitRenderLayers change). All changes connect to the #275 objective. The summary reports no changes to exported or public declarations, dependencies, workflows, or budgets. Limitation: the canvas.ts diff could not be read directly, so the absence of unrelated edits inside that file rests on the change summary.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Fix failing CI checks
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 3cd763a3-b72e-4237-b15b-3437b46f6ffe
Commits
Reviewing files that changed from the base of the PR and between b236dae and 47de34c.
Files selected for processing: 3
.changeset/fast-canvas-layer-composition.md
packages/charts-core/src/canvas-layers.test.ts
packages/charts-core/src/canvas.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
☁️ Nx Cloud last updated this comment at 2026-11-20 16:18:54 UTC
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mixed Canvas/SVG charts can spend quadratic time building their layers. This appends each node once while preserving renderer order and nested group metadata. Thanks @le-marais for the report and reproduction.
Fixes #275.
Summary by CodeRabbit