Skip to content

perf(rendering): reuse shaped text overlay layouts between frames (6.7-8.2x faster) - #2524

Closed
notkainoa wants to merge 2 commits into
CapSoftware:mainfrom
notkainoa:perf/text-overlay-shape-cache
Closed

notkainoa wants to merge 2 commits into
CapSoftware:mainfrom
notkainoa:perf/text-overlay-shape-cache

Conversation

@notkainoa

@notkainoa notkainoa commented Oct 13, 2026 •

Copy link
Copy Markdown

Text overlays are 6.7–8.2x cheaper per frame. The text layer reshaped every overlay from scratch on every frame, even when the text hadn't changed. Now it reuses last frame's layout.

Case Before (p50) After (p50) Speedup
1 title with shadow 34.0 µs 5.1 µs 6.7x
Title + paragraph with background + outlined label 197.0 µs 24.1 µs 8.2x

Runs on every frame of GPUI editor playback, scrubbing and export.

What changed

  • A layout is reused when the content, font, size, letter spacing, alignment and wrap width all match the previous frame.
  • Opacity, position and animations still update every frame. They don't need a reshape.
  • Gradient and staggered reveal passes still reshape, as before.

Output is unchanged

Benchmark setup

TextLayer::prepare at 1920×1080. p50 over 300 frames after 30 warmup frames. Each number is the median of 3 runs. Apple M1, release build, opt-level 3. "Before" is the same benchmark on main (3d19c5c).

CARGO_PROFILE_RELEASE_OPT_LEVEL=3 cargo test -p cap-rendering --release --lib benchmark_text_layer_prepare -- --ignored --nocapture

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issue was found.

Summary

TextLayer now reuses the previous frame’s plain text layouts when all shaping inputs match.

  • Text overlays reuse the previous frame’s layout when its shaping inputs match.

No new actionable issues found. GPU tests were inspected but not run.

Reviews (2) · Last reviewed commit: "test(rendering): check the text layout c..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread crates/rendering/src/layers/text.rs
@notkainoa
notkainoa force-pushed the perf/text-overlay-shape-cache branch from f153054 to d38ae1d Compare October 14, 2026 19:34
@richiemcilroy

Copy link
Copy Markdown
Member

@greptileai review

@richiemcilroy

Copy link
Copy Markdown
Member

Thanks for this! The same per-frame reuse landed on main in 164bfef (crates/rendering/src/layers/text.rs, keyed on the full shaping attributes and colours, so the gradient and stagger passes hit the cache too), which is why this now conflicts. Your reused_layouts_follow_each_shaping_input test is more thorough than main's, since it varies every shaping input in turn. Would you be up for a small PR that ports just that test onto main's cache?

@notkainoa

notkainoa commented Oct 20, 2026 •

Copy link
Copy Markdown
Author

Opened #2739 with just that test on main's cache @richiemcilroy

@richiemcilroy

Copy link
Copy Markdown
Member

Thanks so much for this contribution, @notkainoa! The same per-frame shaped-text reuse landed on main in 164bfef, so this one is covered. Closing this one, but really appreciate the time you put into it.

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.

2 participants