Skip to content

Fix ImageChops.offset for 16-bit modes + speed up - #9975

Merged
hugovk merged 2 commits into
python-pillow:mainfrom
akx:offset-16-fix
Sep 10, 2026
Merged

Fix ImageChops.offset for 16-bit modes + speed up#9975
hugovk merged 2 commits into
python-pillow:mainfrom
akx:offset-16-fix

Conversation

@akx

@akx akx commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Follows up on #9753 (via @hugovk's excellent catch #9753 (review)).

This replaces the whole internal implementation of ImageChops.offset with a much simpler memcpy() pattern rather than computing modulos for every pixel...

@codspeed-hq

codspeed-hq Bot commented Sep 9, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.8

⚠️ 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

⚡ 4 improved benchmarks
✅ 599 untouched benchmarks
⏩ 335 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
test_offset[1237x811-L] 11 ms 1.9 ms ×5.7
test_offset[1237x811-LA] 16.7 ms 7.4 ms ×2.3
test_offset[1237x811-RGB] 16.7 ms 7.4 ms ×2.3
test_offset[1237x811-RGBA] 16.7 ms 7.4 ms ×2.3

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:offset-16-fix (ed627f5) with main (3c7080c)

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 September 9, 2026 11:36
Comment thread src/libImaging/Offset.c Outdated
Comment thread src/libImaging/Offset.c Outdated
Comment thread Tests/test_imagechops.py Outdated

@radarhere radarhere 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.

I've created akx#28 with some suggestions.

@akx
akx marked this pull request as draft September 10, 2026 09:13
@akx

akx commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Oh, I realized there's a much better way to do this still, roundaboutly via @radarhere's suggestion PR...

Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
@akx
akx marked this pull request as ready for review September 10, 2026 10:38
@akx

akx commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author
-Merging this PR will improve performance by 16.37%
+Merging this PR will improve performance by ×2.8

There we go... 😄

@akx akx changed the title Fix ImageChops.offset for 16-bit modes Fix ImageChops.offset for 16-bit modes + speed up Sep 10, 2026
@akx
akx requested review from hugovk and radarhere September 10, 2026 10:41
Comment thread Tests/test_imagechops.py Outdated
@akx
akx requested a review from radarhere September 10, 2026 11:22
Comment thread src/libImaging/Offset.c
@hugovk
hugovk merged commit 9bd66d9 into python-pillow:main Sep 10, 2026
62 checks passed
@akx
akx deleted the offset-16-fix branch September 10, 2026 14:04
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.

3 participants