Skip to content

perf(rendering): reshape captions only when their text or style changes (up to 7.6x faster) - #2526

Merged
richiemcilroy merged 3 commits into
CapSoftware:mainfrom
notkainoa:perf/caption-overlay-shape-cache
Oct 20, 2026
Merged

richiemcilroy merged 3 commits into
CapSoftware:mainfrom
notkainoa:perf/caption-overlay-shape-cache

Conversation

@notkainoa

@notkainoa notkainoa commented Oct 13, 2026 •

Copy link
Copy Markdown

Captions are up to 7.6x cheaper per frame. The captions layer rebuilt and reshaped the caption on every frame, even though in most styles the text and color stay the same for the whole segment. Now it keeps the shaped text and reshapes only when it changes.

Caption style Before (p50) After (p50) Speedup
default 56.7 µs 7.5 µs 7.6x
pill highlight 60.8 µs 11.6 µs 5.2x
outline 84.2 µs 34.8 µs 2.4x
color highlight 65.3 µs 65.5 µs same (unchanged path)

Means: default 55.4 → 11.9 µs, pill 60.1 → 16.0 µs, outline 80.5 → 36.8 µs, color highlight 63.9 → 64.3 µs.

Runs on every frame of GPUI editor playback and export of any recording with captions.

What changed

  • The shaped buffer is kept, and rebuilt only when the caption text, size, wrap width, font, weight or color changes.
  • Per-word color highlighting still reshapes every frame, because its word colors really do change. That path is untouched.
  • Fade frames still reshape. The fade alpha is baked into the shaped glyphs, and the outline passes draw from the same buffer, so reshaping is what keeps the pixels identical to main. Those frames are the remaining p95.

Output is unchanged

Benchmark setup

CaptionsLayer::prepare at 1920×1080: 4 spoken sentences at 60 fps. One warmup pass, then 3 measured passes pooled (824 visible frames per pass, 2,472 total). 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_captions_layer_prepare -- --ignored --nocapture

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable defects remain.

Summary

Keeps shaped caption text between frames and rebuilds it when the text or style changes.

  • Caption rendering reuses shaped text until its text or style changes.

The previous and current commits have different merge bases with the target commit, so this review used the full PR diff.

Reviews (2) · Last reviewed commit: "test(rendering): check the caption layou..." · 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/captions.rs
@notkainoa
notkainoa force-pushed the perf/caption-overlay-shape-cache branch from 3f37e77 to a496dab Compare October 14, 2026 19:34
@richiemcilroy

Copy link
Copy Markdown
Member

@greptileai review

@richiemcilroy
richiemcilroy merged commit 93cfc99 into CapSoftware:main Oct 20, 2026
44 of 46 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.

2 participants