Skip to content

perf(widgets): build the caption glyph Paths once - #599

Open
palmoni5 wants to merge 1 commit into
leanflutter:mainfrom
palmoni5:upstream/caption-glyph-path-cache
Open

palmoni5 wants to merge 1 commit into
leanflutter:mainfrom
palmoni5:upstream/caption-glyph-path-cache

Conversation

@palmoni5

@palmoni5 palmoni5 commented Nov 10, 2026 •

Copy link
Copy Markdown

Problem

The four built-in Chrome caption painters (minimize, maximize, restore, close) rebuild their complete 16x16 glyph, dozens of cubicTo/lineTo calls, on every paint, although the geometry is constant.

Change

Each painter keeps its glyph in a lazily initialized static final Path. The geometry depends on neither the color nor the paint size (the icon is always laid out at 16x16 and never scaled or mirrored), so there is nothing to invalidate: the device pixel ratio is applied by the canvas transform, and the color stays in the per-paint Paint. Memory is bounded to four Path objects per isolate. Rendering output is unchanged; the gain is small per frame and was not benchmarked.

Tests

New test/window_caption_path_cache_test.dart: for each glyph, in light and dark themes, the painted path fills and leaves empty characteristic points (geometry unchanged; these assertions also pass against the old painters), the same Path instance is drawn across repaints (fails against the old painters), and glyph types do not share a Path.

dart format --set-exit-if-changed ., flutter analyze (package and example) and flutter test (package and example) pass locally (Flutter 3.47.7, Windows), and the full CI workflow passes on the identical commit in my fork.

Related

Part of a set of independent PRs, each based on main and mergeable on its own: widgets #598, #599 (this), #600, #601; legacy bridge #602, #603, #604, #605, #606.

Touches window_caption_button.dart like #598 (caption button states); the two merge cleanly in either order.

The four Chrome caption painters rebuilt their whole 16x16 glyph (dozens
of cubicTo/lineTo calls) on every paint. The geometry depends on neither
the color nor the paint size, so each painter now keeps it in a lazily
initialized static final Path; the color stays in the per-paint Paint.

Tests check that each glyph still fills and leaves empty its
characteristic points in both themes, that a glyph draws the same Path
object across repaints, and that glyph types do not share a Path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant