Skip to content

Apply hoist optimizations to Geometry.c's transforms - #9788

Open
akx wants to merge 1 commit into
python-pillow:mainfrom
akx:faster-geometry-1
Open

akx wants to merge 1 commit into
python-pillow:mainfrom
akx:faster-geometry-1

Conversation

@akx

@akx akx commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Like the other recent optimization PRs: hoist im*->xsize and im*->ysize into locals so autovectorization can do its thing.

@codspeed-hq

codspeed-hq Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 19.6%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 21 improved benchmarks
✅ 582 untouched benchmarks
⏩ 335 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
test_rotate_right[1237x811-L-ROTATE_180] 8.5 ms 6.2 ms +36.32%
test_rotate_right[1237x811-L-FLIP_LEFT_RIGHT] 8.5 ms 6.2 ms +36.3%
test_scale[1237x811-LA-2.14-NEAREST] 101.9 ms 84.6 ms +20.45%
test_scale[1237x811-I-2.14-NEAREST] 101.8 ms 84.6 ms +20.37%
test_scale[1237x811-F-2.14-NEAREST] 101.9 ms 84.7 ms +20.33%
test_scale[1237x811-RGBA-2.14-NEAREST] 101.9 ms 84.7 ms +20.29%
test_scale[1237x811-RGB-2.14-NEAREST] 101.9 ms 84.7 ms +20.28%
test_rotate_right[1237x811-LA-ROTATE_180] 14.1 ms 11.9 ms +18.87%
test_rotate_right[1237x811-RGBA-FLIP_LEFT_RIGHT] 14.1 ms 11.9 ms +18.87%
test_rotate_right[1237x811-RGBA-ROTATE_180] 14.1 ms 11.9 ms +18.86%
test_rotate_right[1237x811-LA-FLIP_LEFT_RIGHT] 14.1 ms 11.9 ms +18.86%
test_rotate_right[1237x811-RGB-FLIP_LEFT_RIGHT] 14.1 ms 11.9 ms +18.81%
test_rotate_right[1237x811-RGB-ROTATE_180] 14.1 ms 11.9 ms +18.8%
test_scale[1237x811-F-0.8-NEAREST] 16.5 ms 14.1 ms +17.07%
test_scale[1237x811-RGB-0.8-NEAREST] 16.5 ms 14.1 ms +17.07%
test_scale[1237x811-LA-0.8-NEAREST] 16.5 ms 14.1 ms +17.07%
test_scale[1237x811-RGBA-0.8-NEAREST] 16.5 ms 14.1 ms +17.07%
test_scale[1237x811-I-0.8-NEAREST] 16.5 ms 14.1 ms +17.06%
test_transform[1237x811-LA-BICUBIC-PERSPECTIVE] 385.7 ms 337.7 ms +14.23%
test_transform[1237x811-LA-BICUBIC-AFFINE] 347.5 ms 304.3 ms +14.18%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

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:faster-geometry-1 (4ae228a) with main (0a61c53)

Open in CodSpeed

Footnotes

  1. 335 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.

@akx
akx marked this pull request as ready for review July 11, 2026 06:51
@akx
akx force-pushed the faster-geometry-1 branch from ffd82f2 to 1a8290d Compare July 20, 2026 07:43
Comment thread src/libImaging/Geometry.c
int in_xsize = imIn->xsize, in_ysize = imIn->ysize;
int out_xsize = imOut->xsize, out_ysize = imOut->ysize;

if (in_xsize != out_xsize || in_ysize != out_ysize) {

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.

Could you explain how this is an improvement? I mean, it wasn't using the values within a loop. There was no repetition at all.

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.

You mean out_xsize/out_ysize? Yes, they're not used in the loops, but I think it reads more cleanly for the human reader if it's

if (in_xsize != out_xsize || in_ysize != out_ysize) {

and not

if (in_xsize != imOut->xsize || in_ysize != imOut->ysize) {

-- with the latter, at least my code eye starts wondering why there's two different idioms for the sizes.

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.

Yes, that is what I was referring to. This appears to be another different of opinion - your instinct is to wonder why the code is written differently, my instinct is to wonder why the code is more complex than it could be.

We'll see how #9962 goes. It is merged, then this discussion becomes irrelevant.

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.

My opinion about this isn't strong at all, but it's a consistency thing a tiny bit like #9975 (comment) - it's a little easier to read if all of the similar functions have the same prelude.

@akx akx mentioned this pull request Jul 29, 2026
@akx
akx force-pushed the faster-geometry-1 branch from 1a8290d to cb14785 Compare August 10, 2026 18:45
@akx
akx force-pushed the faster-geometry-1 branch from cb14785 to 4ae228a Compare September 13, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants