Skip to content

perf(desktop-gpui): presize flattened RGB buffer - #2718

Open
kyzer1023 wants to merge 1 commit into
CapSoftware:mainfrom
kyzer1023:cursor/presize-flatten-rgb-66ec
Open

kyzer1023 wants to merge 1 commit into
CapSoftware:mainfrom
kyzer1023:cursor/presize-flatten-rgb-66ec

Conversation

@kyzer1023

@kyzer1023 kyzer1023 commented Oct 19, 2026 •

Copy link
Copy Markdown

Summary

flatten_rgba_to_rgb_over_white built its output with a per-pixel extend_from_slice. It now allocates vec![0u8; rgba.len() / 4 * 3] once and writes each pixel into dst[i..i + 3], using the same three alpha branches and the same blend. rgba_to_rgb and encode_jpeg_rgba_as_rgb are untouched.

Files: apps/desktop-gpui/kernels/src/codec.rs and a bench case in apps/desktop-gpui/kernels/benches/frame_export.rs. Based on main at 85219015.

Correctness

Output is byte-identical to the old loop for opaque, fully transparent, and mixed-alpha buffers, including a hand-checked alpha == 128 pixel. cap-gpui-kernels lib tests: 42 passed, 1 ignored, on rustc 1.88.0 and 1.99.1. The full desktop-gpui app was not built here because gpui is patched to a local zed-cap checkout.

Benchmarks

Measured under the profile desktop-gpui ships with (its own workspace: opt-level = 3, lto = "thin", codegen-units = 1, strip = "symbols"), rustc 1.99.1, 4 vCPU. Each run is 5 warmups and the median of 25 samples; the table is the median of 5 runs. 3840×2160.

Workload Before After Speedup
Opaque 7.888 ms 6.349 ms 1.24×
Fully transparent 8.593 ms 5.091 ms 1.69×
Mixed alpha 7.937 ms 8.105 ms 0.98×

Opaque frames (the common share case) and transparent frames are faster. Mixed alpha is about 2% slower on stable and flat on 1.88.0.

Overlap

Does not touch rgba_to_rgb / encode_jpeg_rgba_as_rgb (#2672) or PNG filtering (#2674).

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge; no actionable issues were found.

Summary

flatten_rgba_to_rgb_over_white now sizes the RGB buffer upfront and writes pixels into it directly.

  • Screenshot JPEG exports build flattened RGB frames without per-pixel appends.

No actionable issues found. Tests and benchmarks were inspected, not run.

Reviews (1) · Last reviewed commit: "perf(desktop-gpui): presize flattened RG..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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