Skip to content

perf(gpui): reduce PNG filter scoring work - #3539

Open
tadhgdowdall wants to merge 1 commit into
CapSoftware:mainfrom
tadhgdowdall:perf/gpui-png-filter-scoring
Open

tadhgdowdall wants to merge 1 commit into
CapSoftware:mainfrom
tadhgdowdall:perf/gpui-png-filter-scoring

Conversation

@tadhgdowdall

@tadhgdowdall tadhgdowdall commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

PNG export scores each candidate row filter by summing absolute signed-byte values. The current 64-bit reductions over 32-byte chunks spend unnecessary work widening and reducing those values. This uses 16-bit reductions over 256-byte chunks, then widens each chunk total to 64 bits.

Each byte contributes at most 128, so a chunk sums to at most 32,768 and cannot overflow u16. The scores remain exact, preserving filter selection, tie behavior and encoded PNG bytes. This benefits screenshot Save and Copy, transparent Share, and PNG writing during image import. Opaque Share uses the existing JPEG path.

Performance

Compared against main af9a65a91808739dc4386c29eea569fbe08c2d4e on an AMD Ryzen 5 3600, 6 cores / 12 threads, Linux x86_64. Both variants run in the same executable with matching locked dependencies and GPUI release settings: Rust 1.95.0, optimization level 3, thin LTO, one codegen unit and stripped symbols.

Each input used two excluded warm-up pairs followed by 24 fresh-process pairs, alternating before/after order. There were 480 measured processes, with no measured samples removed. Times below are milliseconds; reductions use the median. p95 uses nearest rank.

Input Resolution Median before Median after Time reduction p95 before p95 after
Synthetic UI 3840×2160 74.101 66.489 10.3% 74.494 67.311
Synthetic gradient 3840×2160 29.215 21.609 26.0% 29.558 22.201
Synthetic noise 3840×2160 161.804 151.838 6.2% 164.596 156.625
Synthetic solid color 3840×2160 15.401 14.251 7.5% 16.094 14.441
GPUI window screenshot 660×872 26.044 24.876 4.5% 26.799 25.230
Editor screenshot 984×400 6.112 4.727 22.7% 6.174 4.766
Social image 1246×654 19.606 18.614 5.1% 22.043 20.601
Sequoia photograph 4000×2500 41.068 31.657 22.9% 42.073 33.196
Sonoma photograph 4000×2500 127.589 116.224 8.9% 135.887 128.401
Small photograph control 330×330 6.716 6.313 6.0% 6.809 6.382

Measurements cover the complete PNG encoder, including allocation, filtering, worker creation, compression and PNG assembly. They exclude source reading and decoding, input construction, destruction of the returned PNG, filesystem writes, GPU rendering, annotation compositing, app scheduling, dialogs and clipboard preparation. These are encoding-phase improvements, not end-to-end export or FPS measurements. Photographs were decoded to RGBA before timing and encoded as PNG.

All ten measured inputs produced byte-identical before/after PNG files with unchanged sizes. The real inputs are repository assets under apps/web/public/blog/gpui/, apps/web/public/features/, apps/web/public/og.png, apps/desktop/src-tauri/assets/backgrounds/macOS/ and apps/desktop-gpui/assets/images/. Benchmark code, synthetic fixtures and raw samples remain outside the committed diff.

Correctness and validation

  • Added an in-repository regression test with 5,145 exact score comparisons. It covers empty input, every length from 0 through 1,025, 256-byte chunk boundaries and tails, large inputs, all byte values, patterned/random data, and repeated signed-minimum bytes.
  • The regression test detects both intentional local mutations: enlarging the narrow chunks enough to overflow, and interpreting signed bytes as unsigned values. Neither mutation is in this change.
  • The native kernel library suite passed 74 tests, with one existing benchmark ignored. A later focused run passed all five PNG tests, including RGB/RGBA round trips across strip counts, IDAT splitting and fallback behavior.
  • An external release differential test passed 88 cases, comparing both filtered bytes and complete PNG bytes against main across RGB/RGBA layouts, odd dimensions, patterns and strip thresholds. These external cases are not part of CI coverage.
  • Locked kernel compilation, production-library Clippy with warnings denied, scoped formatting and git diff --check passed.
  • Strict library-and-test Clippy remains blocked by two existing diagnostics in thumbnail.rs: manual_is_multiple_of and manual_div_ceil. Both reproduce on unchanged main.
  • Full native-app compilation fails on both main and this branch because the local GPUI checkout lacks GlassStyle, paint_glass and activate_window_with_token.

Only apps/desktop-gpui/kernels/src/png.rs changes, including the regression test. The implementation uses safe, portable Rust and leaves public APIs, dependencies, allocation and threading behavior unchanged.

Native UI interaction, end-to-end export latency, macOS/Windows runtime behavior and performance on other CPUs/toolchains remain unverified.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Speeds up PNG filter scoring by summing 256-byte chunks in u16, then widening each total to u64.

  • PNG filter scores use larger chunks and narrower sums.

Reviews (1) · Last reviewed commit: "perf(gpui): reduce PNG filter scoring wo..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 29, 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.

@tadhgdowdall
tadhgdowdall force-pushed the perf/gpui-png-filter-scoring branch from 4a2cefc to 72e07ea Compare October 31, 2026 10:26
@vercel

vercel Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Oct 31, 2026 10:26am UTC

@vercel
vercel Bot temporarily deployed to Preview – cap-status October 31, 2026 10:26 Inactive

This branch was previously deployed

1 inactive deployment
Preview – cap-status — 72e07ea1 Deployed Oct 31, 2026 by vercel[bot]
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.

1 participant