Repository navigation
perf(frame): simd improvement & unpadded frames in one pass - #2484
Conversation
|
this is built on top of my prev PR: #2478 , (closed it as both changes are combined here) |
richiemcilroy
left a comment
There was a problem hiding this comment.
Reviewed the conversion and both production callers. Local comparisons matched the previous output across 112 valid layouts and reproduced the speedup. Full native CI is still running.
|
Merged, thanks @viralcodex! Nice improvement to the frame conversion path, with clear before/after numbers. Appreciate you contributing to Cap 🫡 |
Hey my pleasure @richiemcilroy, I saw the post on X so though to take the gamble, installed Cap and recorded my first video too for my package i'm about to release, really love what u made here! |
Problem
GPUI's CPU-backed editor preview converts padded RGBA frames to tightly packed BGRA before uploading them to the sprite atlas. The same conversion runs in the portable camera-blur path.
The per-pixel
copy_from_slice(&[...])produces an expensive SIMD instruction sequence. At 4K, this conversion alone takes approximately 1.65 ms per frame.Solution
In
frame.rs, replace the temporary array and slice copy with direct channel writes:This lets LLVM generate a shorter SIMD load/store sequence. Padding handling, input validation, allocation, and output bytes remain unchanged. No unsafe code or platform-specific implementation is added.
Benchmark
Actual production function versus the previous implementation, using synthetic RGBA frames with 256-byte-aligned strides. Apple M4 Pro, Rust 1.88.0,
rustc -O, 15 interleaved measured batches after warmup. Medians per conversion, including allocation:This saves approximately 0.92 ms per 4K conversion. These are kernel measurements, not end-to-end playback or export timings. The macOS IOSurface preview path bypasses this conversion.

Confidence Score: 5/5
This PR appears safe to merge.Summary
unpad_rgba_to_bgranow removes row padding and swaps red and blue in one pass.Reviews (1) · Last reviewed commit: "simd improvement" · Reviewed by Greptile