Repository navigation
perf(desktop-gpui): write copy_rows output once instead of zero-filling first - #3138
Merged
richiemcilroy merged 1 commit intoOct 24, 2026
Conversation
…ng first copy_rows backs every non-macOS camera preview frame (mirrored by default) and the library/import/clip thumbnail buffers. It allocated with vec![0; len] and then overwrote every byte, so each frame was written twice. Non-mirrored rows now extend a with_capacity Vec; mirrored rows reverse straight into spare capacity. Output is byte-identical. frame_copy_rows bench, Apple M2: 1.28-1.67x across camera 720p/1080p (mirrored and not), 4K import and thumbnail workloads.
Contributor
|
@shaileshvats is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cap_gpui_kernels::frame::copy_rowsbuilds the BGRA buffer behind every non-macOS camera preview frame (feeds::camera_preview_image, mirrored by default) and the decoded-frame buffers for library thumbnails, imports and clip thumbnails. It allocated its output withvec![0; len]and then overwrote every byte, so each call wrote the whole frame twice.This PR writes each output byte exactly once:
Vec::with_capacityplus oneextend_from_sliceper row, so there's no zero-fill pass.as_chunks::<4>(), then a singleset_len. This is the same spare-capacity patternunpad_rgba_to_bgraalready uses. The row reversal stays azip(... .rev())over[u8; 4]chunks, which LLVM vectorizes. An indexedsource[last - i]loop measured about 4× slower, so I didn't use one.row_bytesisn't a multiple of 4, and everyNonecase is unchanged.This doesn't overlap with #2668. That PR adds a fast path for unpadded, non-mirrored frames, but it keeps the zero-fill for padded rows and for the mirrored camera path that this PR targets.
Benchmarks
New
benches/frame_copy_rows.rs, in the same style asframe_unpad: the old implementation is inlined asbaseline, outputs are asserted equal, before/after runs alternate within one build, 5 warmup and 30 measured samples per workload. Strides are padded the way ffmpeg/wgpu pad them (64- or 256-byte aligned).Apple M2, rustc 1.99.1,
cargo bench -p cap-gpui-kernels --bench frame_copy_rows. Median of 30 samples; speedup range across three separate runs:At 30 fps, a mirrored 1080p camera preview spends about 3 ms less per second in this copy.
Testing
copy_rows_matches_a_zeroed_copy_for_every_shapechecks the new code against the old zero-then-copy behaviour. It covers zero rows, zerorow_byteswith zero and non-zero stride, tight and padded strides, RGB24 rows, rows that aren't a multiple of 4 (mirrored and not), and a 256-byte-aligned BGRA stride.cargo test -p cap-gpui-kernels --lib frame::: 11 passed.rustfmt --checkis clean on the touched files.cargo clippy -D warnings: the touched code is clean. Stable clippy 1.99 still flags the existingswap_red_blue(chunks_exact_mut(4)), which this PR doesn't change.I couldn't run the full desktop-gpui workspace locally:
[patch."https://github.com/wingleeio/zed"]points at a siblingzed-capcheckout, andcap-audioneeds system ffmpeg. So I built and tested theframemodule and this bench in a standalone crate with the same release profile (lto = "thin",codegen-units = 1).

Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
copy_rowsavoids zero-filling its output before copying frame bytes.No actionable issues found. Build and test commands were not run during this review.
Reviews (1) · Last reviewed commit: "perf(desktop-gpui): write copy_rows outp..." · Reviewed by Greptile