Skip to content

Optimize pixel map operations#2978

Open
RunDevelopment wants to merge 1 commit into
image-rs:mainfrom
RunDevelopment:map-pixels
Open

Optimize pixel map operations#2978
RunDevelopment wants to merge 1 commit into
image-rs:mainfrom
RunDevelopment:map-pixels

Conversation

@RunDevelopment
Copy link
Copy Markdown
Member

This adds 2 internal functions, map_pixels and map_pixels_in_place, that I used to re-implement color operations. These new functions contain fast paths based on ::to_pixel_view and ::to_pixel_view_mut.

Interestingly, this did not speed up color operations as much as I expected:

grayscale               time:   [2.4140 ms 2.4304 ms 2.4528 ms]
                        change: [-41.028% -40.272% -39.548%] (p = 0.00 < 0.05)
                        Performance has improved.

grayscale_alpha         time:   [2.7753 ms 2.8050 ms 2.8409 ms]
                        change: [-42.708% -41.901% -41.093%] (p = 0.00 < 0.05)
                        Performance has improved.

invert                  time:   [2.9125 ms 2.9882 ms 3.0735 ms]
                        change: [-25.416% -22.636% -19.695%] (p = 0.00 < 0.05)
                        Performance has improved.

Note: The benchmark for invert makes a full copy of the input image before applying the operation. This probably eats a lot of the improvement.

Still good, but I expected more. I suspect that the branch predictor helped a lot before.

Anyway, I only ported 3 functions for now. I'd like to do brighten and co in a separate PR, because I want to take this chance to remove their code duplication.

Open questions:

  • Should the fast path be dyn? All code is currently monomorphized over both the image type and operations type. This is unnecessary since all image types can share one copy without loss in performance.
  • Should the new methods be part of GenericImage and GenericImageView? They seem useful for users.

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