Skip to content

Speed up alpha_composite, matrix, negative, quantize#9740

Open
akx wants to merge 6 commits into
python-pillow:mainfrom
akx:faster-loops-small
Open

Speed up alpha_composite, matrix, negative, quantize#9740
akx wants to merge 6 commits into
python-pillow:mainfrom
akx:faster-loops-small

Conversation

@akx

@akx akx commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Refs #9649, #9675, #9736, #9737, #9738, #9739 (same series, same techniques).

These were a couple lines each, so I figured I'd bundle them into one PR.

@codspeed-hq

codspeed-hq Bot commented Jun 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×3.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

⚡ 6 improved benchmarks
✅ 323 untouched benchmarks
🆕 6 new benchmarks
⏩ 2 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
test_invert[1024x1024-LA] 24.9 ms 4.5 ms ×5.6
test_invert[1024x1024-RGBA] 24.9 ms 4.5 ms ×5.6
test_invert[1024x1024-RGB] 24.9 ms 4.5 ms ×5.5
test_invert[1024x1024-L] 6.3 ms 1.2 ms ×5.4
test_matrix_convert[1024x1024-L-matrix0] 13.5 ms 6.5 ms ×2.1
test_matrix_convert[1024x1024-RGB-matrix1] 28.9 ms 19.8 ms +46.1%
🆕 test_alpha_composite[1024x1024-LA-mixed] N/A 26.7 ms N/A
🆕 test_alpha_composite[1024x1024-LA-opaque] N/A 26.8 ms N/A
🆕 test_alpha_composite[1024x1024-LA-transparent] N/A 9.6 ms N/A
🆕 test_alpha_composite[1024x1024-RGBA-mixed] N/A 26.7 ms N/A
🆕 test_alpha_composite[1024x1024-RGBA-opaque] N/A 26.8 ms N/A
🆕 test_alpha_composite[1024x1024-RGBA-transparent] N/A 9.6 ms N/A

Tip

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


Comparing akx:faster-loops-small (633c164) with main (6590b1b)

Open in CodSpeed

Footnotes

  1. 2 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 June 30, 2026 10:54
@hugovk

hugovk commented Jun 30, 2026

Copy link
Copy Markdown
Member

test_alpha_composite is new in this PR, what speedups did you get locally?

@akx

akx commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

test_alpha_composite is new in this PR, what speedups did you get locally?

It's actually an expansion of the old test_alpha_composition benchmark that didn't test some of the more interesting cases. Renamed so it doesn't confuse CodSpeed.

---------------------- benchmark 'composition': 6 tests, 2 sources ----------------------
Name (time in us)                                    0013_al0 Min  0014_al1 Min      ΔMin
-----------------------------------------------------------------------------------------
test_alpha_composite[1024x1024-LA-transparent]           557.3750      465.1660    -16.5%
test_alpha_composite[1024x1024-RGBA-transparent]         557.8750      458.8330    -17.8%
test_alpha_composite[1024x1024-LA-mixed]               2,364.1250    2,346.4580     -0.7%
test_alpha_composite[1024x1024-LA-opaque]              2,381.0420    2,357.4580     -1.0%
test_alpha_composite[1024x1024-RGBA-mixed]             2,382.4590    2,327.3750     -2.3%
test_alpha_composite[1024x1024-RGBA-opaque]            2,409.9580    2,370.7500     -1.6%
-----------------------------------------------------------------------------------------

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