Skip to content

Optimize histogram generation + fix masked histograms for 2-band images + add test coverage - #10005

Merged
radarhere merged 3 commits into
python-pillow:mainfrom
akx:histo-opt
Sep 17, 2026
Merged

radarhere merged 3 commits into
python-pillow:mainfrom
akx:histo-opt

Conversation

@akx

@akx akx commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Follows up on #9050
Follows up on #9054
Follows up on #9752 (comment)

This applies similar hoist/restrict optimizations as the earlier optimization PRs.
While doing that, I noticed the masked/non-masked loops were curiously different, and it looks like #9054 was never applied to the masked case.

I also noticed the masked path for histograms didn't have actual test coverage (they were incidentally covered by e.g. autocontrast), so now they do.

@codspeed

codspeed Bot commented Sep 16, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 66.4%

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

⚡ 2 improved benchmarks
✅ 607 untouched benchmarks
⏩ 338 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
test_histogram_masked[1237x811-L] 13.3 ms 7.1 ms +88.85%
test_histogram_masked[1237x811-LA] 21.4 ms 14.6 ms +46.62%

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:histo-opt (349c6ca) with main (26ddd05)

Open in CodSpeed

Footnotes

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

@akx
akx marked this pull request as ready for review September 16, 2026 07:30
Comment thread src/libImaging/Histo.c
Comment thread src/libImaging/Histo.c Outdated
Comment thread docs/releasenotes/13.0.0.rst Outdated
Comment thread docs/releasenotes/13.0.0.rst Outdated
Comment thread Tests/test_image_histogram.py Outdated
Comment thread Tests/test_image_histogram.py Outdated
Comment thread Tests/test_image_histogram.py Outdated
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@radarhere
radarhere enabled auto-merge September 17, 2026 05:32
@radarhere
radarhere merged commit 63a63d6 into python-pillow:main Sep 17, 2026
41 of 58 checks passed
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