Skip to content

perf(gpui): reduce camera and picker pixel conversion work - #2513

Merged
richiemcilroy merged 3 commits into
CapSoftware:mainfrom
tadhgdowdall:perf/gpui-pixel-conversion
Oct 18, 2026
Merged

richiemcilroy merged 3 commits into
CapSoftware:mainfrom
tadhgdowdall:perf/gpui-pixel-conversion

Conversation

@tadhgdowdall

@tadhgdowdall tadhgdowdall commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

The portable camera-blur preview currently copies each BGRA frame and then makes a second pass to swap red and blue. This combines the copy and channel swap into one pass while retaining the reusable output buffer.

Picker conversion now writes directly into the final output buffer, bulk-copying RGBA rows and using fixed channel permutations for BGRA, ARGB, and ABGR. Row bounds are validated before allocation, avoiding an unused output allocation for truncated input.

These changes use safe Rust and preserve alpha and pixel values. They introduce no resampling, colour conversion, compression, or encoding changes.

Benchmarks

Measured against baseline 3d19c5cfa, using Rust 1.95.0, as specified by the GPUI build scripts and CI, with matching locked dependencies and the GPUI release settings: optimisation level 3, thin LTO, and one codegen unit.

Hardware: AMD Ryzen 5 3600, Linux x86_64.

Two runs pinned to logical CPU 2, each using five warm-up iterations followed by 50 measured before/after pairs per workload. Measurement order alternated. Results below combine 100 pairs per workload.

All timings are microseconds per conversion.

Workload Median before Median after Time reduction p95 before p95 after
Camera, 640×360, reused buffer 140.57 117.78 16.2% 181.97 139.41
Picker BGRA, 320×180 75.16 32.27 57.1% 96.45 34.40
Picker RGBA, 320×180 66.34 7.63 88.5% 96.55 8.10
Picker ARGB, 320×180 81.51 46.16 43.4% 96.46 50.26
Picker ABGR, 320×180 48.01 32.19 32.9% 75.47 34.60

These dimensions reflect the current camera-blur limit and picker thumbnail size. Timings include output allocation where applicable; setup, equality assertions, and output destruction are excluded.

Camera conversion with a fresh allocation was approximately unchanged: 439.42 → 432.74 µs. The main camera improvement occurs when reusing the buffer across frames. Additional padded-row and growing/shrinking-buffer cases also improved.

Larger stress cases did not improve uniformly: cold 4K camera conversion measured approximately 1% slower. That size exceeds the current portable camera-blur limit.

These measurements cover the conversion functions, rather than application FPS or total export duration. Benchmark code and raw results are kept outside the repository.

Correctness and validation

  • Native kernel tests: 25 passed, with one existing benchmark ignored.
  • Added focused regression tests for multiple padded rows (including absent final-row padding), a truncated second row, and zero stride with sufficient and short input.
  • Locked native checks, Clippy with warnings denied, and formatting checks passed.
  • More than 530,000 external comparisons against the original implementation verified byte-for-byte equality across channel orders, arbitrary byte values, unaligned input, trailing partial pixels, padded and overlapping rows, zero stride, empty dimensions, and truncated input.
  • Allocation checks covered 255 buffer states. Stable camera-buffer reuse remains allocation-free; valid row conversions retain the same allocation count and size.
  • The changed conversion source passed compile checks for macOS ARM64 and Windows MSVC.

Native GPUI interaction, hardware camera capture, macOS/Windows runtime behaviour, and end-to-end export were not exercised.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with the previous test-coverage finding fully addressed.

Summary

The PR reduces pixel-copy work in camera previews and picker thumbnails.

  • Camera frames swap red and blue in one pass.
  • Picker pixels convert directly into RGBA output.

The added tests were checked against the code but were not run during this review.

Reviews (3) · Last reviewed commit: "test(gpui): cover pixel conversion row b..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@tadhgdowdall is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

Comment on lines +123 to +126
let readable_rows = match raw_data.len().checked_sub(row_bytes) {
None => 0,
Some(_) if bytes_per_row == 0 => height,
Some(remaining) => remaining / bytes_per_row + 1,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 New row checks lack tests

convert_32bit_rows now checks all row bounds before copying, but the retained tests only use one row. They cannot catch mistakes in the new row-count calculation or rejection of a truncated later row. The comparisons described in the PR are kept outside the repository, so CI cannot repeat them.

Add kernel tests for multiple padded rows, a truncated second row, and zero stride with both sufficient and short input.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/kernels/src/frame.rs
Line: 123-126

Comment:
**New row checks lack tests**

`convert_32bit_rows` now checks all row bounds before copying, but the retained tests only use one row. They cannot catch mistakes in the new row-count calculation or rejection of a truncated later row. The comparisons described in the PR are kept outside the repository, so CI cannot repeat them.

Add kernel tests for multiple padded rows, a truncated second row, and zero stride with both sufficient and short input.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 74bf2ec

@richiemcilroy

Copy link
Copy Markdown
Member

Thanks for the PR. Greptile left open feedback on this and there is no confidence score for the current head. We only merge PRs once Greptile scores the current head 5/5, so please address its comments, then comment @greptileai to request a re-review until it reaches 5/5.

@tadhgdowdall

Copy link
Copy Markdown
Contributor Author

@greptileai review

@tadhgdowdall

Copy link
Copy Markdown
Contributor Author

Thanks for the PR. Greptile left open feedback on this and there is no confidence score for the current head. We only merge PRs once Greptile scores the current head 5/5, so please address its comments, then comment @greptileai to request a re-review until it reaches 5/5.

Thanks @richiemcilroy, that's done now

@richiemcilroy
richiemcilroy merged commit b89c528 into CapSoftware:main Oct 18, 2026
36 of 38 checks passed
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