Skip to content

FIX: Avoid unbounded allocations for float markevery - #32150

Merged
QuLogic merged 4 commits into
matplotlib:mainfrom
sahilmathur254:fix/32133-bug-memoryerror-in-mark-every-path-w
Aug 7, 2026
Merged

QuLogic merged 4 commits into
matplotlib:mainfrom
sahilmathur254:fix/32133-bug-memoryerror-in-mark-every-path-w

Conversation

@sahilmathur254

Copy link
Copy Markdown
Contributor

PR summary

The large allocation appears to come from constructing the full
len(marker_delta) × len(delta) distance matrix. This avoids materialising both
the full marker_delta sequence and the 2D distance matrix, preserves the existing
float markevery placement semantics, and adds extreme-zoom plus parity coverage.

Closes #32133

Validation:

  • The reported extreme-zoom reproduction completes without the previous 239 GiB allocation.
  • Focused line/markevery tests: 12 passed.
  • Ruff: passed for the two changed files.
  • git diff --check: passed.

AI Disclosure

This PR includes AI-assisted code understanding to speed up the process; the implementation and tests were updated and reviewed manually with AI assistance.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with general and docstring guidelines

@sahilmathur254
sahilmathur254 marked this pull request as ready for review July 31, 2026 16:14

@rcomer rcomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sahilmathur254 it looks like you have come up with some neat solutions, though I admit it took a bit of time for me to get my head around it!

One general point on the tests: I think it has been discussed elsewhere that we generally only put tests on public functions, not private ones. Hopefully another maintainer can comment on that.

Comment thread lib/matplotlib/lines.py Resolved
Comment thread lib/matplotlib/lines.py Resolved
Comment thread lib/matplotlib/lines.py Resolved
Comment thread lib/matplotlib/lines.py Resolved
Comment thread lib/matplotlib/tests/test_lines.py Resolved
Comment thread lib/matplotlib/tests/test_lines.py Resolved
@sahilmathur254

Copy link
Copy Markdown
Contributor Author

@rcomer I moved the actual regression and non-positive spacing coverage to the public draw path.
I retained two focused helper-level tests for exact vertex-selection and tie/repeated vertex semantics, since asserting those precisely through the public API would require heavier image comparisons.
Happy to adjust those as well if the maintainers prefer a strict public only testing policy.

@tacaswell tacaswell added this to the v3.11.2 milestone Aug 4, 2026
@tacaswell

Copy link
Copy Markdown
Member

Labeled for back-port as asking for 300G is definitely a bug, but will not argue if anyone disagrees about backporting.

@rcomer rcomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sahilmathur254 I just have a comment about the error message and then I think this is good to go.

Comment thread lib/matplotlib/lines.py Resolved
@rcomer

rcomer commented Aug 6, 2026

Copy link
Copy Markdown
Member

Labeled for back-port as asking for 300G is definitely a bug, but will not argue if anyone disagrees about backporting.

I think we are fine as long as nobody is currently passing a negative step. That would currently be a roundabout way of not getting any markers, so an odd thing to do.

Comment thread lib/matplotlib/tests/test_lines.py Resolved
Comment thread lib/matplotlib/lines.py Resolved
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>

@rcomer rcomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone can merge when CI is green.

@QuLogic
QuLogic merged commit 0f760fb into matplotlib:main Aug 7, 2026
51 of 84 checks passed
rcomer added a commit that referenced this pull request Aug 7, 2026
…150-on-v3.11.x

Backport PR #32150 on branch v3.11.x (FIX: Avoid unbounded allocations for float markevery)
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.

[Bug]: MemoryError in _mark_every_path (with float markevery) when extreme zooming in

5 participants