Skip to content

Conversation

@QuLogic
Copy link
Member

@QuLogic QuLogic commented Jan 21, 2026

PR summary

According to memray, these tests use fairly large amounts of memory:

  • lib/matplotlib/tests/test_simplification.py::test_throw_rendering_complexity_exceeded: 2.2GiB
  • lib/matplotlib/tests/test_agg.py::test_chunksize_fails: 2.0GiB
  • lib/matplotlib/tests/test_image.py::test_large_image[png-col-16777216-2\*\*24 rows-upper]: 1.0GiB
  • lib/matplotlib/tests/test_image.py::test_large_image[png-col-16777216-2\*\*24 rows-lower]: 1.0GiB
  • lib/matplotlib/tests/test_image.py::test_downsample_interpolation_stage[png]: 1.0GiB
  • lib/matplotlib/tests/test_lines.py::test_invisible_Line_rendering: 822.0MiB
  • lib/matplotlib/tests/test_image.py::test_large_image[png-row-8388608-2\*\*23 columns-lower]: 537.8MiB
  • lib/matplotlib/tests/test_image.py::test_large_image[png-row-8388608-2\*\*23 columns-upper]: 537.8MiB

The next closest tests use just 216MiB, then 145.5MiB, etc. and then the majority under 100MiB.

If you're unlucky, with 4-way xdist you might use upwards of 6GiB RAM if you get all these on separate processes.

The above tests are all fairly low-level checks for Agg renderer limits that are not likely to change often, so skip them by default unless on CI.

PR checklist

@QuLogic
Copy link
Member Author

QuLogic commented Jan 21, 2026

Hmm, looking at test_downsample_interpolation_stage, it passes with a 40x40 image instead of 4000x4000; does it even need to be that big?

@timhoffm
Copy link
Member

I propose to delete lib/matplotlib/tests/test_lines.py::test_invisible_Line_rendering.

The test tries to confirm that visible == False returns early. It does so by creating large data, that should produce a noticable delay when being processed.
If one wanted to test this, a better strategy would be to assert that x, y are not touched during draw using mocking. But overall, what are we trying to prevent here? The test would only fail if the if not self.is_visible(): return code would be moved further down again. That is highly unlikely. If we would write draw() from scratch with this early return, we would not add a test for the early return. So let's KISS and just delete it.

By cutting the grid by one-tenth in each dimension, this cuts memory
usage from 1.0GiB to 65.2MiB. I temporarily added an assert in
`_ImageBase._make_image` to confirm that the interpolation stage did
correctly switch to 'rgba' as well.
This test tries to check for slowdowns, which is inherently flaky (as
noted by the comment), and we don't check `set_visible` for other
artists.
@QuLogic
Copy link
Member Author

QuLogic commented Jan 22, 2026

Okay, I removed that test and reduced the memory usage for test_downsample_interpolation_stage.

@QuLogic QuLogic force-pushed the skip-big-tests branch 2 times, most recently from 60e2f0c to 7c98478 Compare January 22, 2026 05:12
@QuLogic
Copy link
Member Author

QuLogic commented Jan 22, 2026

So it turns out that pytest_addoption doesn't work if conftest.py is installed, so I've switched to checking an environment variable (but it should also continue to enable these tests on CI as well.)

According to memray, these tests use fairly large amounts of memory:
- lib/matplotlib/tests/test_simplification.py::test_throw_rendering_complexity_exceeded: 2.2GiB
- lib/matplotlib/tests/test_agg.py::test_chunksize_fails: 2.0GiB
- lib/matplotlib/tests/test_image.py::test_large_image[png-col-16777216-2\\*\\*24 rows-upper]: 1.0GiB
- lib/matplotlib/tests/test_image.py::test_large_image[png-col-16777216-2\\*\\*24 rows-lower]: 1.0GiB
- lib/matplotlib/tests/test_image.py::test_large_image[png-row-8388608-2\\*\\*23 columns-lower]: 537.8MiB
- lib/matplotlib/tests/test_image.py::test_large_image[png-row-8388608-2\\*\\*23 columns-upper]: 537.8MiB

The next closest tests use just 216MiB, then 145.5MiB, etc. and then the
majority under 100MiB.

If you're unlucky, with 4-way xdist you might use upwards of 6GiB RAM if
you get all these on separate processes.

The above tests are all fairly low-level checks for Agg renderer limits
that are not likely to change often, so skip them by default unless on
CI.
Comment on lines +55 to +56
Some tests may use a large amount of memory (>0.5GiB); to enable those tests, set the
environment variable ``MPL_TEST_HIGH_MEMORY``.
Copy link
Member

@timhoffm timhoffm Jan 22, 2026

Choose a reason for hiding this comment

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

Do we want to generalize to "expensive tests"? This could include runtime as well as memory.
The 14 slowest tests together take 120s.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure we have too many that take long; I guess just the sphinx docs one, maybe?

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