Speed up ImageMath - #10072
Open
akx wants to merge 2 commits into
Open
Speed up ImageMath#10072akx wants to merge 2 commits into
akx wants to merge 2 commits into
Conversation
Merging this PR will improve performance by 38.12%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_imagemath_unary[1237x811-I-abs] |
23.2 ms | 15.8 ms | +46.39% |
| ⚡ | test_imagemath_unary[1237x811-I-neg] |
22.7 ms | 15.7 ms | +44.65% |
| ⚡ | test_imagemath_binary[1237x811-I-lt] |
29.1 ms | 20.8 ms | +40.35% |
| ⚡ | test_imagemath_binary[1237x811-I-min] |
29.8 ms | 21.3 ms | +39.83% |
| ⚡ | test_imagemath_binary[1237x811-I-add] |
28.8 ms | 20.7 ms | +39.02% |
| ⚡ | test_imagemath_binary[1237x811-I-mul] |
29.1 ms | 22.1 ms | +31.54% |
| ⚡ | test_imagemath_scalar[1237x811-I] |
33 ms | 26.2 ms | +26.16% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing akx:fast-math (e06ae60) with main (685e78a)
Footnotes
-
338 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements the usual hoist + restrict optimizations (and documents the contracts for that) for ImageMath. It also fixes float division to vectorize (yes, we divide by zero first, and only then check if we made an oopsie).
Something I didn't address here is that ImageMath apparently allocates a dummy image for scalar operations, which is wasteful memory-wise and slower, but fixing that would involve a new category of scalar operations in the C code (maybe some 300? lines?).
On my machine, some operations speed up by half, some not much: