lowe-lab-ucl / arboretum

Track and lineage visualization with btrack and Napari :evergreen_tree:
MIT License
45 stars 11 forks source link

Increase rendering performance #78

Closed quantumjot closed 2 years ago

quantumjot commented 2 years ago

I did some profiling of the rendering code using examples/show_large_tree.py and 255 nodes (depth 8):

255 total nodes
         7509808 function calls (7448213 primitive calls) in 4.881 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    4.881    4.881 base_plotter.py:50(draw_from_nodes)
      892    0.005    0.000    4.370    0.005 visuals.py:125(__init__)
      509    0.002    0.000    2.784    0.005 vispy_plotter.py:110(add_branch)
      892    0.004    0.000    2.626    0.003 visual.py:325(__init__)
      509    0.004    0.000    2.552    0.005 vispy_plotter.py:156(add_track)

It looks like a lot of the time is in adding subvisuals, so I had a go at setting things up with a single subvisual for all branches. This gets the performance to a much better state:

255 total nodes
         121140 function calls (119670 primitive calls) in 0.138 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.140    0.140 base_plotter.py:50(draw_from_nodes)
      509    0.001    0.000    0.100    0.000 vispy_plotter.py:110(add_branch)
      509    0.006    0.000    0.086    0.000 vispy_plotter.py:88(autoscale_view)
6777/6009    0.023    0.000    0.046    0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}
        1    0.009    0.009    0.036    0.036 tree.py:35(layout_tree)

0.14 seconds versus 4.88 seconds. We will probably want to look at the graph searching algorithms at some point, but this is a good start.

This also merges the small changes in #77, so I will close that one.

napari-arboretum

deprecated-napari-hub-preview-bot[bot] commented 2 years ago

Preview page for your plugin is ready here: https://preview.napari-hub.org/lowe-lab-ucl/arboretum/78 Updated: 2022-07-01T15:38:27.392683

KristinaUlicna commented 2 years ago

Just checked the performance on some larger trees, it works great! 🚀

codecov-commenter commented 2 years ago

Codecov Report

Merging #78 (7e21492) into main (bb23b25) will decrease coverage by 2.98%. The diff coverage is 96.20%.

@@            Coverage Diff             @@
##             main      #78      +/-   ##
==========================================
- Coverage   96.28%   93.30%   -2.99%     
==========================================
  Files          16       16              
  Lines         538      612      +74     
==========================================
+ Hits          518      571      +53     
- Misses         20       41      +21     
Impacted Files Coverage Δ
napari_arboretum/visualisation/base_plotter.py 91.86% <75.00%> (-0.83%) :arrow_down:
napari_arboretum/visualisation/vispy_plotter.py 85.13% <97.10%> (-12.40%) :arrow_down:
napari_arboretum/plugin.py 89.06% <100.00%> (ø)
napari_arboretum/tree.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bb23b25...7e21492. Read the comment docs.

KristinaUlicna commented 2 years ago

Looks great! :) All trees show, the single-branch tracks are centred and the performance seems to be better than before (didn't run into the kernel crashing yet). But in the meantime, we lost the y-axis next to the tree [as in #46].