Skip to content

Improve RankFilter/MinFilter/MaxFilter (performance + I;16 support) - #10558

Merged
radarhere merged 5 commits into
python-pillow:mainfrom
radarhere:filter
Nov 19, 2026
Merged

radarhere merged 5 commits into
python-pillow:mainfrom
radarhere:filter

Conversation

@radarhere

Copy link
Copy Markdown
Member

Parts of #10045

  • applies the familiar hoist + restrict optimizations to ImagingExpand (which underpins RankFilter), and makes it correct for 16-bpc data
  • applies hoist and restrict and other optimizations to RankFilter.c.
    • As a side effect, this cleans up the nearly-single-use IMAGING_PIXEL_<dtype> macros from _imaging.h. They were only used in RankFilter (which no longer does image row pointer acquisition for every pixel) and in 2 places in _imaging.c.
  • adds support for I;16 modes

akx and others added 5 commits November 19, 2026 13:33
This removes the `IMAGING_PIXEL_(type)` macros from `Imaging.h` too;
they were only used in `RankFilter.c` and in one place in `_imaging.c`.
@codspeed

codspeed Bot commented Nov 19, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 11%

3 warnings

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

⚡ 3 improved benchmarks
✅ 665 untouched benchmarks
⏩ 352 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_rank_filter[1237x811-L-Median3] 267.6 ms 240.2 ms +11.43%
⚡ test_rank_filter[1237x811-L-Min3] 268.8 ms 241.3 ms +11.39%
⚡ test_rank_filter[1237x811-L-Median5] 500.9 ms 454.7 ms +10.17%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing radarhere:filter (f53584a) with main (431dc39)

Open in CodSpeed

Footnotes

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

@radarhere
radarhere merged commit 9823d78 into python-pillow:main Nov 19, 2026
94 of 98 checks passed
@radarhere
radarhere deleted the filter branch November 19, 2026 04:07
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