Skip to content

Speed up rectangle, polygon and line drawing - #9772

Open
akx wants to merge 10 commits into
python-pillow:mainfrom
akx:faster-rect-and-line
Open

akx wants to merge 10 commits into
python-pillow:mainfrom
akx:faster-rect-and-line

Conversation

@akx

@akx akx commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Since hline is the primitive used for scanline-filling polygons, this will speed that up too (especially in the translucent cases), there's just no benchmark for it (yet? I can add one).

In the RGB(A) hline case, the speedup is unswitch (two unswitches actually) and autovectorization.

And the -97.3% reduction below is just... not painting when the ink is entirely translucent. 😄

Note

Stacked on #9982 now because they touch the same things, but that one's primarily a correctness fix. It's probably easier to review that first, then I can rebase this.

@akx
akx marked this pull request as ready for review July 6, 2026 12:10
@akx
akx force-pushed the faster-rect-and-line branch from 0355c20 to c74ec6a Compare July 20, 2026 07:36
@akx akx mentioned this pull request Jul 29, 2026
@akx
akx force-pushed the faster-rect-and-line branch from c74ec6a to da8eb6a Compare August 10, 2026 18:41
@codspeed

codspeed Bot commented Aug 10, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×3

⚠️ 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
✅ 620 untouched benchmarks
⏩ 338 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
test_draw_lines_blend[1237x811-0] 1,028 µs 85.4 µs ×12
test_draw_lines[1237x811-L] 912.5 µs 380.2 µs ×2.4
test_draw_lines_blend[1237x811-255] 1,025.2 µs 460.9 µs ×2.2
test_draw_lines_blend[1237x811-127] 1,025.7 µs 768.3 µs +33.51%

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-rect-and-line (d06bef6) with main (4b03987)

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 force-pushed the faster-rect-and-line branch from da8eb6a to e7903cb Compare September 6, 2026 16:05
@akx
akx marked this pull request as draft September 10, 2026 12:07
@akx
akx force-pushed the faster-rect-and-line branch 2 times, most recently from 81701ae to b8961b8 Compare September 11, 2026 13:55
@akx
akx force-pushed the faster-rect-and-line branch from b8961b8 to d06bef6 Compare September 22, 2026 09:06
@akx
akx marked this pull request as ready for review September 22, 2026 11:09

This branch has not been deployed

No deployments
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