Skip to content
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

Drops in playback performance when loading napari-TSP #25

Open
rjlopez2 opened this issue May 27, 2023 · 5 comments
Open

Drops in playback performance when loading napari-TSP #25

rjlopez2 opened this issue May 27, 2023 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@rjlopez2
Copy link
Contributor

Hi Chris,

I have seen a slightly decrease in performance for rendering some relatively modest size timestacks in napari when using your pluging.
I have been thinking for some time now how to address this problem but may be you could give me a better insight on this and may be take me to the right track on how to fix this.

Here is a way to reproduce the issue:

  1. create a clean test environment
conda create -n test_env python=3.9
conda activate test_env
python3 -m pip install "napari[all]"
pip install napari-time-series-plotter
  1. Try to add an image (approximately the same size of our use case images) directly in the napari interpreter or a Jupyter-notebook
from numpy.random import default_rng

rng = default_rng()

data = rng.standard_normal((500, 500, 1500))

viewer.add_image(data)
  1. set the playback configuration to 60 FPS (you should be able to see a responsive and no lagging playback)

image

  1. Load your plugin

  2. See the increased latency in the playback of the current image

  3. close your plugin

  4. playback speed comes back to normal

Do you have an idea what could be the reason of this drops in performance when I load your plugin?

best

Ruben

@rjlopez2 rjlopez2 changed the title playback of timestacks Drops in playback performance when loading napari-TSP May 27, 2023
@Chris-N-K
Copy link
Owner

Chris-N-K commented May 27, 2023

I think I can explain the hit to performance. Every time the slice changes a new draw event is triggered, as the plugin draws the current z slice. The current implementation of the draw function is relatively performance heavy as the whole canvas is cleared and redrawn. Matplotlib is not perfect for such an application.

I already have an improved version of the drawing machinery but it will still be somewhat resource heavy when combining it with the playback function. In the current version the data acquisition and the drawing is one function, in the new version they are separate. This might help.

I might have some time this week and will run some tests with the new functions.

Thanks for reporting. :)
Anything else you noticed?

@rjlopez2
Copy link
Contributor Author

thanks for the fast reply!

Every time the slice changes a new draw event is triggered, as the plugin draws the current z slice. The current implementation of the draw function is relatively performance heavy as the whole canvas is cleared and redrawn. Matplotlib is not perfect for such an application.

on this, I don't know if this tips mentioned here by Juan-Nunez might be of interest.

I was also thinking on using/implemented some other recommendations from the Napari documentation such as multithreading those task that are computational consuming and are independent of the main thread e.g average a ROI. Do you think that that make sense?

Anyway, from now that's all. I look forward to see your results and check out the version you are working on.

Cheers

Ruben

@Chris-N-K
Copy link
Owner

Chris-N-K commented May 30, 2023

@rjlopez2 I can reproduce your observations. The fps drop if the plugin is docked, it is not necessary to select a layer and actually plot. I think I have to review which event triggers the plotting. Seems like it causes redraws in situations when it shouldn't.
Big thanks for reporting this.

Thanks for the pointer to Juan-Nunez's post, that's exactly the thing I try in the new implementation.

  1. Only draw plots anew if they change
  2. Try to keep the objects and only update them

It's somewhat tricky to keep track with as small an overhead as possible, but I think it will work.
At the moment the changes are only in my local repository, will probably push them the moment the first draft works properly.

@Chris-N-K Chris-N-K added the bug Something isn't working label May 31, 2023
@Chris-N-K Chris-N-K added this to the Version 0.1.0 milestone May 31, 2023
@Chris-N-K Chris-N-K self-assigned this May 31, 2023
@Chris-N-K
Copy link
Owner

Hi @rjlopez2 ,
I fixed in my rework of the plugin, the playback performance is no longer affected at all.
I will close this issue as soon as the changes go live.

@rjlopez2
Copy link
Contributor Author

Thanks @Chris-N-K!
I look forward to check this out and thanks for your work.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants