Some remarks/questions about perceived slowness of matplotlib

In make_image, most of the time is taken into to_rgba:

    > almost half of it is taken in by the take call in the
    > Colormap.__call__. Almost 200 ms to get colors from the
    > indexes seems quite a lot (this means 280 cycles / pixel on
    > average !). I can reproduce this number by using a small
    > numpy test.

    > On my laptop (pentium M, 1.2 Ghz), make_image takes almost
    > 85 % of the time, which seems to imply that this is where
    > one should focus if one wants to improve the speed,

This may have been lost in the longer thread above, but what
interpolation are you using? You may see a good performance boost by
using interpolation='nearest'. Also, with your clip changes and with
Eric's changes is it still painfully slow for you -- how much have
these changes helped? Of time time spent in make image, how much is
_image.fromarray, ScalarMappable.to_rgba and _image.resize?

John Hunter wrote:

    > In make_image, most of the time is taken into to_rgba:
    > almost half of it is taken in by the take call in the
    > Colormap.__call__. Almost 200 ms to get colors from the
    > indexes seems quite a lot (this means 280 cycles / pixel on
    > average !). I can reproduce this number by using a small
    > numpy test.

    > On my laptop (pentium M, 1.2 Ghz), make_image takes almost
    > 85 % of the time, which seems to imply that this is where
    > one should focus if one wants to improve the speed,

This may have been lost in the longer thread above,

I am a bit lost myself between numpy and mpl ML, sorry for the inconvenience.

but what
interpolation are you using? You may see a good performance boost by
using interpolation='nearest'.

At what point is interpolation used ?

Also, with your clip changes and with
Eric's changes is it still painfully slow for you

Painfully is a strong word :slight_smile: It is still 10 to 15 times slower than matlab on the same computer: the show call is around 800 ms instead of 70 ms with matlab, and matlab image is equivalent to imshow + show calls actually. Matlab having only one toolkit, it obviously has an advantage, but I don't think the problem is on the GUI side anyway.

-- how much have
these changes helped?

With the original profiling, it took a bit more than 2100 ms for a show call after a imshow call for a 8000x256 array according to a saved kcachegrind profile. Now, it is around 800 ms, which is already much better, and with minimal changes (eg without using a special fast path more prone to bugs). I estimate that squeezing to a bit less than 500 ms should be easily possible by improving on numpy side (clip, float to int convertion and take function), which has the nice effect of improving mpl without touching one line of it, and improving numpy as the same time :slight_smile:

The last 500 ms would be much more difficult to squeeze: half of it is used to 'launch' the figure anyway. And below a few hundred ms, it is becoming unnoticeable in interactive use (whereas the change from 2.1 s to 0.8 is; on my laptop, it is even more noticeable, because its CPU is kind of slow).

David