Repository navigation
improve(desktop-gpui): 23-34x faster pixelate masks in the screenshot editor - #2555
FranprzDev wants to merge 3 commits into
Conversation
|
@FranprzDev is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
|
Performance improve by my agent btw |
|
Local check run on the current head ( Run on Linux arm64 with Rust 1.95.0 in an isolated copy of
The bench numbers in this single run are higher than the table in the description because the VM was busier; the table (3 runs, n=60) is the one to go by. The failing Vercel checks are "Authorization required to deploy" for |
|
Thanks for the PR. Greptile's 5/5 was for 2477474, and new commits have landed since, so the current head hasn't been scored. We only merge once the current head is 5/5. Please comment |
fb93238 to
f308d7d
Compare
|
@greptileai please check |
|
@richiemcilroy Greptile is back to 5/5 on the current head (f308d7d). Ready to merge whenever you are, thanks! |
f308d7d to
b414ed9
Compare
|
@greptileai please review the latest head (b414ed9), rebased onto current main. |
|
Hi @richiemcilroy can you authorize the deploy? |
|
@greptileai please review the latest head (ab9c38c), which is main merged into the branch. No code changes on our side. |

What changes
cap_gpui_kernels::screenshot::mask_filterwithpixelate = true(the screenshot editor's Pixelate mask, which is the type a new mask gets, at the default level 16) no longer copies the region into anRgbaImageand runsimage::imageops::resize(.., FilterType::Nearest)twice (down tosize / block, then back up).It now computes, once per call, which source column and which source row every output pixel lands on after those two nearest-neighbour resizes, then fills the output straight from the frame: one 4-byte copy per pixel of a new row, and a whole-row
extend_from_withinfor every row that repeats the previous one (all but one row per block).The index mapping is the one
image0.25 uses forFilterType::Nearest:resizeruns the box kernel with zero support throughvertical_sample/horizontal_sample, which always picks the single source pixelclamp(floor((out + 0.5) * (in as f32 / out as f32)), 0, in - 1)with weight 1.0, so composing that mapping twice is byte-identical to the old output. The Blur branch (FilterType::Triangle) is unchanged.Also adds:
kernels/benches/screenshot_mask.rs, a before/after bench in the style ofscreenshot_blit.rs: the previous implementation is kept asmod baseline, both outputs are asserted equal for every workload before timing, before/after order alternates, results are printed as CSV;pixelate_matches_two_nearest_resizes) that compares the new path with the old two-resize reference across regions at the frame edges, 1×1 regions, odd sizes and levels from 1 to 100.Why
Every mask build in the screenshot editor runs this per mask (moving, resizing or changing the level of a mask rebuilds its overlay), and the export's mask pass runs it again over each mask's region. For a 4K screenshot the old path spent most of its time converting to and from
Rgba32Fintermediates and sampling pixel by pixel withget_pixel/put_pixel, even though nearest-neighbour sampling only ever copies pixels.Impact
Median time per
mask_filter(.., pixelate = true, ..)call, 3 runs × 20 measured pairs per workload (after 5 warm-up pairs each), pinned to one core, Rust 1.95.0 (the toolchain CI uses forcap-gpui-kernels), GPUI release profile settings (opt-level = 3,lto = "thin",codegen-units = 1).Measured on an ARM Neoverse-V2 Linux VM (2 vCPUs); absolute numbers will differ on Apple silicon and x86, but the removed work (two float resampling passes and two intermediate
Rgba32Fbuffers per mask) is the same on every target.Validation
screenshot.rsunit tests pass, including the existing blit tests and the newpixelate_matches_two_nearest_resizes.cargo fmt --checkandcargo clippy --all-targets -- -D warnings(1.95.0) are clean.Cargo.lockis untouched.I ran tests, clippy and the bench on Linux in an isolated copy of the kernels crate (same sources, same
image0.25.10 asCargo.lock), because the full GPUI workspace needs the localzed-capcheckout. I did not run the macOS app itself.

Confidence Score: 5/5
The PR appears safe to merge; no actionable defects were found.Summary
Speeds up screenshot pixelation by copying sampled pixels directly and reusing repeated rows.
Reviews (6) · Last reviewed commit: "Merge branch 'main' into perf/gpui-pixel..." · Reviewed by Greptile