Skip to content

GPUI: faster frames (balanced BoundsTree, cheaper text painting and scene finish) - #3887

Merged
richiemcilroy merged 3 commits into
mainfrom
gpui-perf/frame-pipeline
Nov 6, 2026
Merged

richiemcilroy merged 3 commits into
mainfrom
gpui-perf/frame-pipeline

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Adds zed-perf.patch to the GPUI patch stack: CPU-side frame work gets cheaper on every platform, and every frame draws exactly the same scene as before.

What changes

flowchart TD
  D[Window::draw] --> R[render + request_layout]
  D --> L[taffy layout]
  D --> P[prepaint / paint]
  D --> F[Frame::finish]
  P --> T[paint_line: glyphs]
  P --> S[Scene::insert_primitive]
  S --> B[BoundsTree::insert<br/>draw order]
  F --> E[carry element state]
  F --> SF[Scene::finish: sort primitives]
  classDef hot fill:#ffe2b8,stroke:#c77700
  class B,T,SF,E,L hot
Loading
  • BoundsTree is a balanced R-tree (crates/gpui/src/bounds_tree.rs).
    • Before, a full node never split: inserts nested one level deeper, so a frame's primitives, arriving in paint order, built long chains. One insert cost 5–6.5k instructions.
    • Replaying a cached view re-inserts every primitive it painted, which made this 43% of a cached-view frame on Linux (callgrind).
    • Now all entries sit in leaves at one depth, an overflowing node splits along its longer axis, and each node keeps its subtree's highest order for pruning.
    • The answer is defined purely by the bounds: 1 + max(order of earlier bounds that intersect). It is unchanged, and new tests check it against a brute-force scan on UI-shaped and random frames of up to 6 000 bounds.
  • Scene::finish sorts (key, index) pairs, then permutes in place (scene.rs). Primitives are ~100 bytes and a stable sort moves each several times. Since every index is unique, an unstable sort of the pairs gives exactly the stable order. It skips work when the list is already sorted, and its scratch buffer is reused.
  • Text painting (text_system/line.rs, window.rs):
    • paint_line resolves subpixel rendering once per run and glyph dilation once per color instead of per glyph. On macOS the former takes the native window's lock.
    • paint_line_background returns early when no run has a background. The layer is still pushed, so draw orders don't move.
  • No copies or allocations on hot cache hits (text_system.rs, elements/text.rs, font_features.rs):
    • shape_line and layout_line key the line cache without copying the text first.
    • Text measurement only checks a LineWrapper out of the pool when it truncates.
    • FontFeatures::default() shares one empty list instead of allocating one inside every Window::text_style().
    • shape_text no longer reserves 32 decoration runs (~3 KB) per line.
  • Element-state carry-over (window.rs). Frame::finish only scans the keys that reuse_prepaint / reuse_paint copied from the previous frame. with_element_state already moves every other key's state on first access, so the old scan over all keys could never find them.
  • Taffy keeps one per-node { bounds, outer_origin } map instead of two maps that were always written, read and evicted together (taffy.rs).

Results

Window::draw CPU time per frame, from the frame benchmarks in #3886: base is this branch's parent stack, head is this PR. The M4 is a dedicated Mac mini, 5 interleaved rounds. Windows and Linux are Blacksmith CI VMs, also 5 rounds; VM noise is ±10–30% per round, so mixed rounds on those columns are inconclusive.

Benchmark M4 base → head Windows Linux
cached_panels 637 → 486 µs −23% 489 → 230 µs −52% 703 → 456 µs −37%
primitives_8192 6.62 → 2.90 ms −56% 6.70 → 3.97 ms −43% 6.31 → 3.69 ms −43%
primitives_1024 438 → 422 µs −2% 352 → 246 µs −30% 329 → 221 µs −35%
paragraphs_12 405 → 279 µs −31% 108 → 97 µs −13% 287 → 236 µs −16%
paragraphs_48 1.08 → 0.80 ms −26% 282 → 258 µs −9% 796 → 712 µs −13%
text_rows_static_50 727 → 588 µs −19% 590 → 543 µs −6% 699 → 644 µs −9%
text_rows_static_200 2.06 → 1.65 ms −20% 2.07 → 2.08 ms −8% 2.29 → 2.19 ms −10%
text_rows_changing_50 1.09 → 0.95 ms −13% 651 → 586 µs −5% 889 → 847 µs −8%
text_rows_changing_200 3.52 → 3.10 ms −13% 2.56 → 2.35 ms −3% 3.34 → 3.23 ms −7%
recordings_scroll 410 → 331 µs −19% 319 → 307 µs −3% 402 → 363 µs −9%
hover_cards 3.26 → 2.81 ms −14% 4.38 → 4.12 ms −7% 4.59 → 3.98 ms −16%
cards_64 970 → 836 µs −15% 884 → 785 µs −11% 996 → 883 µs −16%
cards_256 3.34 → 2.73 ms −18% 3.87 → 3.84 ms −11% 3.96 → 4.06 ms −13%
cards_1024 10.14 → 9.17 ms −10% 23.4 → 26.4 ms (rounds −23% … +38%) 22.7 → 23.7 ms −13%

Bold: every round agreed.

The real Cap editor (CAP_GPUI_AUTO_TIMELINE_BENCH, reference recording, release build, M4, 10 interleaved rounds, median Window::draw):

Scenario Base Head Change
clean 1604 µs 1453 µs −9.4%
tick-zoomed-out 3297 µs 3153 µs −5.2%
tick 3226 µs 3127 µs −4.4%
tick-fields 3577 µs 3395 µs −3.8%
follow 3547 µs 3507 µs −1.5%
hover 2269 µs 2238 µs +1.1%
caption-download 9081 µs 9084 µs ±0

Same pixels

  • The scene-equivalence gate from GPUI frame benchmarks: interleaved A/B per platform, scene-equivalence gate, Cap editor A/B #3886 hashes every scene each benchmark submits to the renderer: all primitives, their draw order, and the pixels in every atlas tile they show. Base and head match at all 832 (benchmark, frame) positions across the 14 benchmarks.
  • paint_tests.rs paints multi-color text through a rasterizing test text system and checks that every glyph sprite carries its own color's dilation, and that background runs still paint (and nothing else does).
  • reused_element_state_tests checks that a cached view's element state survives frames where the view is reused.

🤖 Generated with Claude Code

@sandchest-com

sandchest-com Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Sandchest

Sandchest reviewed f64b15b: nothing exploitable found in this change.

Sandchest reviews every change for vulnerabilities an attacker could use · 2 credits · Review details

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 3 other findings in Capy.

Open in Capy

@richiemcilroy
richiemcilroy force-pushed the gpui-perf/frame-pipeline branch from 75eaecd to d011b6f Compare November 6, 2026 13:57
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Ignored Ignored Preview Nov 6, 2026 2:07pm UTC

richiemcilroy and others added 3 commits November 6, 2026 14:02
… caches

Adds zed-perf.patch to the GPUI patch stack:
- shape_line/layout_line no longer copy the text on every call
- paint_line_background skips its per-glyph walk when no run has a background
- paint_line resolves subpixel rendering and dilation once per run/color
- text measurement only checks out a LineWrapper when truncating
- FontFeatures::default shares one empty list instead of allocating
- Frame::finish only scans element-state keys copied by view reuse
- taffy keeps one per-node absolute layout map instead of two

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lean decoration runs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@richiemcilroy
richiemcilroy force-pushed the gpui-perf/frame-pipeline branch from d011b6f to f64b15b Compare November 6, 2026 14:06

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 2 other findings in Capy.

Open in Capy

@richiemcilroy
richiemcilroy changed the base branch from gpui-perf/bench-harness to main November 6, 2026 15:08
@richiemcilroy
richiemcilroy merged commit 97493ff into main Nov 6, 2026
74 of 77 checks passed
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