Skip to content

Restore performance for line drawing - #10615

Open
akx wants to merge 1 commit into
python-pillow:mainfrom
akx:restore-line-perf
Open

akx wants to merge 1 commit into
python-pillow:mainfrom
akx:restore-line-perf

Conversation

@akx

@akx akx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This is a rebase of 24e3fed from #9772 following the merge of the dashed-drawing PR #9490.

This should walk back the inadvertent performance regression from 30657fb.

A subsequent PR, when I have the PR-opening quota for it, will take a look at the other issues with the dash PR (such as, as I suggested in its comments, precomputing the dashing into a C-side struct to avoid repeated conversion).

@codspeed

codspeed Bot commented Nov 24, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 35.23%

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

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

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

⚡ 6 improved benchmarks
✅ 662 untouched benchmarks
⏩ 352 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_draw_lines[1237x811-L] 677.5 µs 444 µs +52.57%
⚡ test_draw_lines[1237x811-RGBA] 731.4 µs 508.3 µs +43.88%
⚡ test_draw_lines[1237x811-LA] 732 µs 509.1 µs +43.78%
⚡ test_draw_lines[1237x811-RGB] 747 µs 524 µs +42.54%
⚡ test_draw_lines_blend[1237x811-127] 1,086.8 µs 932.1 µs +16.6%
⚡ test_draw_lines_blend[1237x811-255] 1,086.4 µs 931.9 µs +16.57%

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:restore-line-perf (93d5504) with main (af804a5)

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

@akx

akx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Seems to do the trick as expected 😄

@radarhere

Copy link
Copy Markdown
Member

My comment on that PR was

What's left here is, I think, more complex or edge case related than the performance gains are worth.

So it's not clear what you were expecting by re-opening this. We can leave it for someone else to review if you want.

@akx

akx commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

So it's not clear what you were expecting by re-opening this.

To restore line drawing performance to what it was in Pillow 13.0.0, before #9982 was merged.

I don't think you meant to regress drawing performance with 30657fb, or if you did, I'd like to know why.

To be clear, you suggested that commit via akx#37 but CodSpeed didn't run there, and I couldn't tell by reading that it'd regress performance. Before CodSpeed could run and reveal that that commit regressed performance, it had been merged.

@radarhere

Copy link
Copy Markdown
Member

I didn't realise that akx#37 would affect performance, I merely thought that it would simplify the code.

I think performance is balanced against functionality and simplicity, and if closing this PR means that Pillow draws lines slightly slower than Pillow 13.0.0, then ok.

@akx

akx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

I understand you didn't realise it, I didn't realise it either before the Codspeed numbers came in, and I've been trying to fix this ever since. This ended up being more elegant than the GEN_LINE thing anyhow.

Looking at that CodSpeed report, I don't think those are "slightly slower" numbers for the common modes (RGB, RGBA), especially since the fix is pretty simple (and only has that many "pesky backslashes" because clang-format rules force wrapping the block like that).

Anyway, I'm happy to hear what other reviewers think, because a net +18 lines to be 40% more efficient when drawing lines does not sound like a bad tradeoff.

@akx

akx commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

... And as noted above, this would apparently require another reviewer to look at it. @aclark4life, maybe, please?

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