Skip to content

perf(desktop-gpui): fast row blit for opaque picker thumbnails - #2670

Open
nikolas-sapa wants to merge 3 commits into
CapSoftware:mainfrom
nikolas-sapa:perf/gpui-fast-thumbnail-fit
Open

nikolas-sapa wants to merge 3 commits into
CapSoftware:mainfrom
nikolas-sapa:perf/gpui-fast-thumbnail-fit

Conversation

@nikolas-sapa

@nikolas-sapa nikolas-sapa commented Oct 17, 2026 •

Copy link
Copy Markdown

Description

In fit_centered, centering a fitted image onto a newly created transparent canvas currently uses image::imageops::overlay.

Because canvas is already empty ([0, 0, 0, 0]), source-over alpha blending onto it is an identity operation:

  • For opaque source pixels (alpha == 255), overlay runs floating-point alpha calculations, bounds checks, and put_pixel per-pixel.
  • By detecting if the source image is opaque using the existing SIMD is_opaque helper, we can copy rows directly via copy_from_slice, completely bypassing the per-pixel float math and bounds checks.
  • When transparency is present, it falls back to imageops::overlay to preserve identical behavior.

Benchmarks

Tested on Apple Silicon using cargo bench --bench thumbnail_fit:

Workload Width x Height Baseline Candidate Speedup
fitted-wide 320x134 65.1 µs 8.2 µs ~7.9x
fitted-tall 218x180 73.4 µs 11.6 µs ~6.3x
fitted-square 180x180 47.4 µs 8.3 µs ~5.7x
fitted-near-full 320x175 77.6 µs 9.3 µs ~8.3x
upscale 160x90 753 µs 683 µs 1.10x
downscale 640x360 1780 µs 1695 µs 1.05x
downscale-1080p 1920x1080 10.8 ms 10.4 ms 1.04x

Verification

  • cargo test -p cap-gpui-kernels: all 30 tests pass (including fitted_sources_keep_exact_centering_and_transparent_padding, resized_sources_match_lanczos_reference, exact_size_preserves_hidden_rgb_and_source_pixels).
  • Exact bit-level parity verified across all workloads.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge.

Summary

fit_centered now copies opaque thumbnail rows directly into the transparent canvas.

  • Fitted opaque thumbnails now copy rows into the canvas.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into perf/gpui-fast-..." · Reviewed by Greptile

- Replace per-pixel imageops::overlay with row-by-row slice copy when thumbnail is opaque
- Keeps identical bit-for-bit output while skipping per-pixel float alpha blending and bounds checks
- Speedup: 5.7x to 8.3x on fitted thumbnails (e.g. fitted-wide: 65 µs -> 8 µs, fitted-near-full: 77 µs -> 9.3 µs)
@vercel

vercel Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

@nikolas-sapa is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

@richiemcilroy

Copy link
Copy Markdown
Member

@greptileai review

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.

2 participants