Skip to content

Clip width 1 lines to the image - #10610

Open
aclark4life wants to merge 1 commit into
mainfrom
clip-width-1-lines
Open

aclark4life wants to merge 1 commit into
mainfrom
clip-width-1-lines

Conversation

@aclark4life

Copy link
Copy Markdown
Member

Lines of width 1 were not clipped to the image before stepping through them, so the time grew with the length of the line. For example, line((0, 0, 2**30, 1)) on a 16x16 image took 1.24 s. The line deltas were also calculated in int, which could overflow for very distant coordinates.

This clips the line to the image before drawing it, and uses 64-bit arithmetic for the deltas. The example now takes no measurable time.

For dashed lines (#9490, not yet released):

  • The dash position is kept modulo the pattern length, and the pixels skipped before the image edge are counted, so a clipped dashed line keeps the same phase as the full line. Previously should_draw_dash() walked the pattern from the start of the line for each pixel.
  • A pattern whose values add up to 0, such as dash=(0,), now draws nothing, rather than looping forever. Negative values are treated as 0.

🤖 Generated with Claude Code

Only step through the part of a line inside the image, using 64-bit
arithmetic for the line deltas. Keep the dash phase of a clipped dashed
line, and draw nothing for a dash pattern of zero length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codspeed

codspeed Bot commented Nov 24, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 12.86%

2 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

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

❌ 4 regressed benchmarks
✅ 664 untouched benchmarks
⏩ 352 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_draw_lines[1237x811-L] 677.5 µs 783.9 µs -13.58%
❌ test_draw_lines[1237x811-RGBA] 731.2 µs 837.5 µs -12.69%
❌ test_draw_lines[1237x811-LA] 731.9 µs 838.1 µs -12.68%
❌ test_draw_lines[1237x811-RGB] 746.8 µs 853.2 µs -12.47%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing clip-width-1-lines (b86eba0) with main (2647866)

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

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.

1 participant