Repository navigation
perf(desktop-gpui): resize picker thumbnails up to 4.3x faster with identical output - #2586
Open
Theophilus2003 wants to merge 3 commits into
Open
Theophilus2003 wants to merge 3 commits into
Theophilus2003 wants to merge 3 commits into
Conversation
Contributor
|
@Theophilus2003 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
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
On Windows and Linux, every recording-picker thumbnail is a full-resolution screenshot of a display or window that
fit_centeredshrinks to 320×180 withimage::imageops::resize(.., Lanczos3). That resize costs 124 ms per 4K display and 49 ms per 1440p display, once per display and window in every thumbnail sweep the picker runs. macOS isn't affected: ScreenCaptureKit captures at 320×180 already.This replaces the call with a Lanczos3 resize in
cap-gpui-kernelsthat is byte-identical toimage's and 2.9x to 4.3x faster on screen-sized sources.How
image's resize runs a vertical pass (into anRgba32Fbuffer) and then a horizontal pass. Every tap goes through a genericget_pixeland fourNumCastconversions, iterating one output pixel at a time down a column.resize_lanczos3keeps the arithmetic identical:sinc/lanczos3kernel, the same tap window (floor/ceil/clamp) and the same weight normalisation;f32accumulation order (taps ascending, starting from0.0, vertical pass first);u8.Only the loop order changes. The vertical pass walks each output row in 32-float blocks that stay in registers, with all taps accumulated before moving on, so it vectorizes. Each output value still sees the same sequence of additions, and Rust never fuses them into FMA, so the result is bit-for-bit the same.
On x86 the vertical pass runs under
#[target_feature(enable = "avx2")]whenis_x86_feature_detected!("avx2"), the same dispatchcrates/rendering/src/cpu_yuv.rsuses. Everything else runs the portable path, which is the identical code compiled for the baseline target.Benchmarks
cargo bench -p cap-gpui-kernels --bench thumbnail_fit, the existing benchmark with five screen-sized workloads added. Each row is the median of 30 alternating samples, 8 fits each. "Before" is the benchmark's existing baseline (imageops::resizewith Lanczos3). x86_64 Linux, 4 vCPU with AVX2.Without AVX2 the portable path measured about 49 ms for the 4K case (≈2.5x). The benchmark asserts that its baseline and
fit_centeredproduce equal images for every workload before it times them.Tests
lanczos3_matches_image_resize_byte_for_byte: random RGBA noise, including alpha, at 3840×2160, 2560×1600, 1920×1080, 1366×768, odd window sizes, an upscale and 1-pixel strips. Every case must equalimage::imageops::resize(.., Lanczos3)exactly.portable_vertical_pass_matches_the_dispatched_one: the AVX2 and portable vertical passes produce bit-identicalf32buffers.resized_sources_match_lanczos_referenceand the otherfit_centeredtests pass unchanged.cargo test -p cap-gpui-kernels(28 passed),cargo clippy -p cap-gpui-kernels --all-targets -- -D warnings,rustfmtclean.

Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Replaces thumbnail resizing with a custom Lanczos3 implementation that works through rows in blocks and selects AVX2 when available.
Reviews (1) · Last reviewed commit: "perf(desktop-gpui): resize picker thumbn..." · Reviewed by Greptile