Skip to content

Skip scratch buffers in the cicp fallback for luma and color pairs - #3147

Open
g4lb wants to merge 3 commits into
image-rs:mainfrom
g4lb:perf-cicp-luma-fallback
Open

g4lb wants to merge 3 commits into
image-rs:mainfrom
g4lb:perf-cicp-luma-fallback

Conversation

@g4lb

@g4lb g4lb commented Nov 13, 2026 •

Copy link
Copy Markdown

For 8 layout pairs, CicpRgb::cast_pixels_by_fallback now converts each pixel in one pass, without the f32 scratch buffers. The pairs are RGB(A) to Luma(A) and Luma(A) to RGB(A). The operations and their order are the same, so output from integer input does not change. Some float values change by 1 ulp, and a NaN alpha in Rgba32F to LumaA8 or LumaA16 now gives the maximum value, not 0. These values are now the same as the values from to_luma32f and to_rgba8.

Conversion (256×256) Before After Change
RGBA8 → Luma8 35.1 µs 17.6 µs −50%
Luma8 → RGBA8 37.9 µs 3.52 µs −91%
LumaA8 → RGB8 41.7 µs 5.8 µs −86%
RGBA32F → Luma8 35.4 µs 16.7 µs −53%
RGBA8 → LumaA8 32.8 µs 19.6 µs −40%
RGB8 → Luma8 19.8 µs 17.3 µs −13%

Compared to the first commit, RGBA32F → LumaA16 is 9% slower because of the NaN check in from_primitive. It is 32% faster than before this PR. I measured no other slowdown on 55 benchmarks. I used 12 interleaved rounds of criterion and a Mann-Whitney test (Apple Silicon, rustc 1.98). I did not measure other architectures.

Checks:

  • cargo test passes with default features, with --no-default-features, and on 1.88 (MSRV).
  • cargo clippy --all-targets -- -D warnings and cargo fmt --check pass.
  • Old and new outputs from integer input matched for all u8 and u16 values, in sRGB, linear and Display P3.

This PR is substantially LLM-generated.

@RunDevelopment RunDevelopment left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR.

I'm not against this, but I vaguely remember maintainers being wary of adding more monomorphized code to color conversions to keep compile times and code size down. You might want to ask your favorite clanker to go through old PRs and issues to get the specifics.

Also, there's definitely still room for improvement regarding performance. I left a few comments if you want to make it even faster.


And don't worry about CI failing.

Comment thread src/metadata/cicp.rs Resolved
Comment thread src/metadata/cicp.rs Resolved
Comment thread src/metadata/cicp.rs Resolved
Comment thread src/metadata/cicp.rs Resolved
@g4lb

g4lb commented Nov 14, 2026

Copy link
Copy Markdown
Author

Thank you. I applied the changes.

@g4lb
g4lb requested a review from RunDevelopment November 15, 2026 10:06
@g4lb

g4lb commented Nov 28, 2026

Copy link
Copy Markdown
Author

@RunDevelopment I applied the changes from your review. Can you look at it again?

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