New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Performance, main] High CPU usage with Shapes/Points when napari is in the background #6223
Comments
The #6222 may be useful for debug such cases. |
The force redraws were added recently in #5737 and #5802. There might be a way to achieve the same thing with an event blocker, but when I tried it was not properly updating the highlights. This seems to work for me: diff --git a/napari/layers/points/points.py b/napari/layers/points/points.py
index db87678ba..91f5d4dc1 100644
--- a/napari/layers/points/points.py
+++ b/napari/layers/points/points.py
@@ -1601,10 +1601,11 @@ class Points(Layer):
def _update_draw(
self, scale_factor, corner_pixels_displayed, shape_threshold
):
+ force_set_highlight = self.scale_factor != scale_factor
super()._update_draw(
scale_factor, corner_pixels_displayed, shape_threshold
)
- self._set_highlight(force=True)
+ self._set_highlight(force=force_set_highlight)
def _get_value(self, position) -> Optional[int]:
"""Index of the point at a given 2D position in data coordinates.
diff --git a/napari/layers/shapes/shapes.py b/napari/layers/shapes/shapes.py
index ffff16775..a351d2b5c 100644
--- a/napari/layers/shapes/shapes.py
+++ b/napari/layers/shapes/shapes.py
@@ -2727,10 +2727,11 @@ class Shapes(Layer):
def _update_draw(
self, scale_factor, corner_pixels_displayed, shape_threshold
):
+ force_set_highlight = self.scale_factor != scale_factor
super()._update_draw(
scale_factor, corner_pixels_displayed, shape_threshold
)
- self._set_highlight(force=True)
+ self._set_highlight(force=force_set_highlight)
def _get_value(self, position):
"""Value of the data at a position in data coordinates. |
May I suggest an approach like #6210 ? It already bring a context manager to batch update. |
I could be wrong, but I'm not sure this issue can be solved only by batching as currently the highlight is updated after drawing using data from the (vispy) draw event. I do think that's a good idea though. I have discussed a bit with @andy-sweet what it would take to remove this feedback event, such as passing camera information (scale, corner pixels) when slicing. This may help avoid similar problems with multiscale images, for example. |
Could you try f9f3d95 ? It does seem to work for me at least for idle, and might be something to build upon ? |
Unfortunately that doesn't work for me, but I'll look closer at how it's working. As-is it doesn't seem to have correct highlighting behavior - basically points highlights don't seem to show up for me (depending on how they are selected). Also the problem of the highlight thickness (solved by #5737) returns. I can fix the behavior if I modify |
In the long term, it would be great to get rid of that feedback/recursive loop. But any quick patch is good enough for now given the severity of the bug. In contrast to multiscale images (where we need corner pixels), I'm actually confused about why the feedback loop is needed for points and shapes. |
I think it just needs to update the highlight thickness based on Another fix would be to treat napari/napari/layers/points/points.py Lines 1852 to 1857 in 14ca578
This still needs |
…CPU background usage) (#6425) I agree something like #6234 is a better long-term fix, but we should do something in the meantime because the high CPU is pretty severe. # References and relevant issues Closes #6223 # Description This breaks a cycle when updating the highlight on Points and Shapes layers. The problem was `_set_highlight` being called with `force=True` in `_update_draw`. This caused a cycle as redrawing the highlights would again call `_update_draw`. This was added to fix the appearance of the highlights during interaction - see #6223 for more discussion. I'm hoping @brisvag can confirm this PR maintains the correct behavior. This PR tracks `scale_factor` the same way `selected_data` and other properties are stored in order to conditionally update the highlight instead of forcing it.
…CPU background usage) (#6425) I agree something like #6234 is a better long-term fix, but we should do something in the meantime because the high CPU is pretty severe. # References and relevant issues Closes #6223 # Description This breaks a cycle when updating the highlight on Points and Shapes layers. The problem was `_set_highlight` being called with `force=True` in `_update_draw`. This caused a cycle as redrawing the highlights would again call `_update_draw`. This was added to fix the appearance of the highlights during interaction - see #6223 for more discussion. I'm hoping @brisvag can confirm this PR maintains the correct behavior. This PR tracks `scale_factor` the same way `selected_data` and other properties are stored in order to conditionally update the highlight instead of forcing it.
…CPU background usage) (#6425) I agree something like #6234 is a better long-term fix, but we should do something in the meantime because the high CPU is pretty severe. # References and relevant issues Closes #6223 # Description This breaks a cycle when updating the highlight on Points and Shapes layers. The problem was `_set_highlight` being called with `force=True` in `_update_draw`. This caused a cycle as redrawing the highlights would again call `_update_draw`. This was added to fix the appearance of the highlights during interaction - see #6223 for more discussion. I'm hoping @brisvag can confirm this PR maintains the correct behavior. This PR tracks `scale_factor` the same way `selected_data` and other properties are stored in order to conditionally update the highlight instead of forcing it.
🐛 Bug
With Shapes and Points layers, there is very high CPU usage when napari is in the background.
Specifically I get >290% CPU and >30% GPU with napari in the background.
(note this does not occur with 0.4.18)
Git Bisect points to: #5802
@andy-sweet has more sleuthing:
To Reproduce
Steps to reproduce the behavior:
Shapes:
Points:
Expected behavior
Minimal if any CPU usage in the background.
Environment
Additional context
Discussion here: https://napari.zulipchat.com/#narrow/stream/212875-general/topic/high.20CPU.20use.20with.20Shapes.20layer
The text was updated successfully, but these errors were encountered: