GeezerVison is showing github.com — Figure.add_image slows down massively as more images are added · Issue #982 · fastplotlib/fastplotlib
Figure.add_image slows down massively as more images are added #982DescriptionPerhaps I'm using the API wrongly, but what I am trying to do is to do some kind of object pooling, having many image graphics pre-initialized since I need to use them as some sort of dynamic thumbnails that show up as the user pans and zooms around, as it is much quicker to just set the data and position on the fly compared to adding a new image graphic, and I will have many of these responding to user interaction, so it needs to be responsive.
I noticed however that as I am initializing more images in the figure, the amount of time it takes to add a new image graphic increases a lot.
I've made a minimal example using imageio and tqdm to illustrate this:
import fastplotlib as fpl
import imageio.v3 as iio
from tqdm import tqdm
img = iio.imread("imageio:astronaut.png")
figure = fpl.Figure()
for x in tqdm(range(2000)):
figure[0, 0].add_image(img)
figure.show()
fpl.loop.run()
Over time, the iterations per second eventually drops to low single digits. This makes the pooling take very long.
This is with fastplotlib 0.6.0, CPython 3.13.5, Windows 11. Activitykushalkolar commented on Jan 26, 2026 I think it's going to be slow with thousands of textures. What's your use case, you probably want to orchestrate your images so that you only display ones which are currently visible, and pre-load some around the edges? Archer6621 commented on Jan 27, 2026 I have a relatively dense 2D point cloud, where each point represents an image, that the user can zoom in on, and when the user zooms in far enough, I want thumbnails of a fixed size to appear at all the points on the screen which I have pre-computed already. I built something custom to do this which works quite well, indeed only showing images on the points that are visible and around the edges to account for images whose points are outside of the view.
I noticed that constantly removing and adding new graphics was slow, so I cache the graphics instead as they get added and then just set their position and data to what I need as the user zooms and pans around, only adding new ones on demand, which is much faster. The warm-up step that I described above simply pretends that a high number of images are demanded from the get-go, just to fill that cache, because this same slow-down appears at runtime whenever a new image graphic gets added when many are present already, hindering interactions.
The rendering of all those images is actually quite alright, it's fast enough to be usable. kushalkolar commented on Jan 27, 2026 Archer6621 commented on Jan 29, 2026
Ah so you mean once they're added it's fast, but the adding itself is very slow? Maybe this is slowing things down as more graphics are added: https://github.com/fastplotlib/fastplotlib/blob/main/fastplotlib%2Flayouts%2F_plot_area.py#L583-L605
Yup that seems to be it, nice find! I commented this piece of code out, and ran the example above again, and it didn't slow down over time anymore. I also ran my original application, same there.
It doesn't seem to impact my application either, as I manually make sure that the scatter points that I have are drawn at an offset that puts them behind the images - for the images themselves I don't care how they overlap.
I suppose it would be nice to somehow make this sorting optional? Or maybe have a way to pre-instantiate many images quickly and then just sorting once. kushalkolar commented on Sep 1, 2026 #1072 is a major refactor of GraphicCollection and will introduce ImageCollection which would be the way to add lots of images to a subplot. kushalkolar commented on Sep 11, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|