bauerdavid/napari-nD-annotator

napari starts lagging when lots of objects are in the object list

Closed this issue · 5 comments

Describe the bug
After adding lots of (in my case 30+) objects to the object list, napari becomes laggy

To Reproduce
Steps to reproduce the behavior:

  1. Open the Object List plugin
  2. Create Bounding box layer
  3. Select lots of bounding boxes
  4. napari is laggy (scrolling through slices, hovering over list elements etc. is slow)

napari info:
napari: 0.4.15
Platform: Windows-10-10.0.22621-SP0
Python: 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)]
Qt: 5.15.2
PyQt5: 5.15.6
NumPy: 1.22.4
SciPy: 1.8.1
Dask: 2022.05.2
VisPy: 0.9.6

OpenGL:

  • GL version: 4.5.0 - Build 25.20.100.6577
  • MAX_TEXTURE_SIZE: 16384

Screens:

  • screen 1: resolution 1920x1080, scale 1.0

Plugins:

  • console: 0.0.4
  • napari-nd-cropper: 0.1.3
  • napari-tools-menu: 0.1.11
  • scikit-image: 0.4.15
  • svg: 0.1.6

Is the recommended workaround here to delete the bounding box layer, then close and reopen the "Object list" widget?

...although the disadvantage there is that you lose the label integer id number, so you need to somehow remember what label id number you were up to.

I've also noticed things freezing & being laggy much sooner than 30 objects (more like 4-8), especially if I try to add a new bounding box mid-way through (i.e. after annotating a handful of other objects).

Is the recommended workaround here to delete the bounding box layer, then close and reopen the "Object list" widget?

...although the disadvantage there is that you lose the label integer id number, so you need to somehow remember what label id number you were up to.

Thanks for the suggestion! I will try it, but as you wrote, we will then loose the current label id. (I was thinking about allowing the user to change the current label, but we'll see whether that makes sense.) The user could also just delete the bounding boxes from the Bounding box layer (without deleting the layer itself), doing so the label id would be kept.

By the way my guess is that too much callbacks are called on interactions, which causes lagging if we have a huge number of objects (probably we have some loop over every element), but I have to check it if this is really the problem.

Perhaps it's not worth including the little image previews if they're part of the reason performance is poor. Perhaps a straight text list would be easier for napari to handle

I revisited this problem, and it actually disappeared. There were some changes made to the ObjectListWidget, and it seems it magically solved this problem.
I also found that there was another source of sluggishness, which was resetting the layer data to force napari to redraw the bounding boxes with different color. But fixing #27 also fixed this problem. Now it runs quite smoothly.
The next version will contain the changes.