Napari: Performance regression for many layers

Created on 23 Nov 2020  路  3Comments  路  Source: napari/napari

馃悰 Bug

As noted in https://forum.image.sc/t/viewer-add-points-significantly-slower-after-upgrade-to-v-0-4/45670/12?u=sofroniewn there was a significant regression in performance with many layers in #1360. I can confirm that it is due to the dynamic calculation of _extent_world https://github.com/napari/napari/blob/v0.4.0/napari/components/layerlist.py#L198 and _step_size https://github.com/napari/napari/blob/v0.4.0/napari/components/layerlist.py#L240 (and the computations they in turn trigger).

The dynamic calculation is very appealing in many ways, but also very time consuming. I'm not quite sure how to fix yet, but making this issue to discuss in more detail.

A minimal example to reproduce the problem is the following

import numpy as np
import napari
from time import time

data = []
for i in range(50):
    data.append(np.random.random((1000, 2)))

viewer = napari.components.ViewerModel()
for i, points in enumerate(data):
    # add the points
    start = time()
    viewer.add_points(points)
    end = time()
    print(f'run {i} in time {end - start}')

which note only runs with the ViewerModel and doesn't need the full Viewer

bug

Most helpful comment

It looks like the same issue as #1885. Here pstat file and graph from the profiling script.

point_speed

point_speed.zip

All 3 comments

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/viewer-add-points-significantly-slower-after-upgrade-to-v-0-4/45670/13

It looks like the same issue as #1885. Here pstat file and graph from the profiling script.

point_speed

point_speed.zip

I'm going to close this as the most significant regression is fixed, though we still have #1949 and #1950 in progress that could bring further speed enhancements

Was this page helpful?
0 / 5 - 0 ratings