plot: Paint grids as quads and cache tessellated line and area paths - #3071
Merged
Merged
Conversation
A chart card repaints on every frame it is on screen — a scrolling list moves it — and profiling the Longbridge AI chat on iOS put the chart cards at 12% of all CPU while visible. Two things dominated: Grid::paint stroked every grid line as a path: lyon tessellation per line, and for dashed grids a path measurement and sampling pass first. Grid lines are axis-aligned, so each line (or each dash) is now a 1px quad centred on the coordinate, which is what the 1px stroke covered. Line::paint and Area::paint tessellated their curves every frame, though the vertices only depend on the projected points relative to the chart origin. PathCache builds a path once at a zero origin and moves its vertices to the frame's origin afterwards; ShapeKey derives the cache key from the projected points and the stroke style; PathCaches keeps a plot's caches in window element state, since plots are values rebuilt on every render. Line::paint_cached and Area::paint_cached use them; the plain paint methods are unchanged. On the AI chat with several cards on screen (iPhone 17 Pro simulator, Release), Grid::paint went from 5.6% to 1.1% of draw time, lyon from 5.3% to 1.1%, and the chart cards' share of draw from 11.6% to 5.3%. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HY6KNBpkTcKkW2PpjrFhji
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
A chart card repaints on every frame it is on screen — a scrolling list moves it — and profiling the Longbridge AI chat on iOS (Time Profiler, iPhone 17 Pro simulator, Release) put the chart cards at 12% of all CPU while visible. Two things dominated:
Grid::paintstroked every grid line as a path: lyon tessellation per line, and for dashed grids aPathMeasurements+ sampling pass first. Grid lines are axis-aligned, so each line (or each dash of one) is now a 1pxpaint_quadcentred on the coordinate — the pixels the 1px stroke covered. Dash segmentation follows the SVGstroke-dasharrayrulesPathBuilderimplements (odd arrays repeat), with unit tests.Line::paint/Area::painttessellated their curves every frame, though the vertices only depend on the projected points relative to the chart origin. New inplot:PathCache— builds a path once at a zero origin and moves its vertices to the frame's origin afterwards;ShapeKey— cache key from the projected points and stroke style;PathCaches— a plot's caches kept in window element state (use_keyed_state), since plots are values rebuilt on every render;Line::paint_cached/Area::paint_cached— opt-in; the plainpaintmethods are unchanged.Adoption in a plot:
Measured on the AI chat with several vis-chart cards and a quote card on screen, same scroll script:
Grid::paintvis_chart_card)StrokeStylegainsHash/PartialEq/Eqso it can key a cache.How to Test
cargo test -p gpui-component --lib plot::— grid dash segmentation and 1px line boxes;PathCachebuilds once per key and translates per origin;ShapeKeychanges with points and extras.cargo runfor story tests related to the changes. (not run — verified in the AI chat on the iOS simulator: dashed grids, bars, pies render as before)🤖 Generated with Claude Code
https://claude.ai/code/session_01HY6KNBpkTcKkW2PpjrFhji