Redrawing an imshow image is ~2x slower in 3.11.0/3.11.1 than in 3.10.9. The slowdown appears for both scalar and RGBA arrays, at both interpolation='none' and 'nearest'.
I noticed because I have an application that redraws a figure containing two imshow artists on every keypress. The app went from ~19 ms to ~40 ms per frame after the matplotlib upgrade, with no code changes.
This table shows the median of the 15 canvas.draw() calls for each matplotlib version. The tests were all run on the same machine, using numpy 2.4.6. I got basically the same results running the test multiple times. It seems like the meaningful change was in 3.11.0.
case
3.10.9
3.11.0
3.11.1
slowdown
scalar array, interp='none'
25.41 ms
49.27 ms
50.70 ms
2.00x
scalar array, interp='nearest'
25.97 ms
56.23 ms
55.67 ms
2.14x
RGBA array, interp='none'
13.17 ms
32.37 ms
32.21 ms
2.45x
RGBA array, interp='nearest'
13.08 ms
33.49 ms
33.26 ms
2.54x
Expected outcome
Restore performance to how it was in 3.10.9
Additional information
I used cProfile when drawing a figure containing two imshow artists. The results from 20 draws are below:
3.10.9 — image.py:585(draw) 0.256 s tottime, matplotlib._image.resample 0.071 s over 80 calls, ndarray.astype 420 calls
3.11.1 — image.py:609(draw) 0.561 s tottime, image.py:350(_make_image) 0.403 s tottime / 0.550 s cumtime, matplotlib._image.resample 0.035 s over 40 calls, ndarray.astype 2720 calls
I've traced the dominant performance hit to the switch to filtering images in premultiplied-alpha space (#29776), which is important for accurate colors when partial transparency is involved (which includes antialiased edges, but that is not relevant for nearest-neighbor interpolation). Speeding up the case of a scalar array should be possible on the Python side, but speeding up the case of an RGBA array with non-uniform alpha would require changes on the C++ side.
Edit: Both #31021 and #31313 also seem to have slightly reduced performance, just not by as much as #29776. It's presumably due to the more accurate nearest-neighbor interpolator implemented/updated in those two PRs.
Activity
ayshih commented on Aug 24, 2026
I've traced the dominant performance hit to the switch to filtering images in premultiplied-alpha space (#29776), which is important for accurate colors when partial transparency is involved (which includes antialiased edges, but that is not relevant for nearest-neighbor interpolation). Speeding up the case of a scalar array should be possible on the Python side, but speeding up the case of an RGBA array with non-uniform alpha would require changes on the C++ side.
Edit: Both #31021 and #31313 also seem to have slightly reduced performance, just not by as much as #29776. It's presumably due to the more accurate nearest-neighbor interpolator implemented/updated in those two PRs.