allen-cell-animated / volume-viewer

https://allen-cell-animated.github.io/volume-viewer/
Other
90 stars 7 forks source link

optimize data arriving at viewer's main thread #204

Closed toloudis closed 3 months ago

toloudis commented 3 months ago

Estimated time to review: 10 min or less.

One of the most expensive operations when playing through time series is shuffling data around when it arrives at the viewer. The following two profiles show 30 seconds of ome-zarr playback of one of our nucmorph colonies, playing in our testbed viewer. In the following profile: packToAtlas is pretty expensive.

Before:

DevTools - localhost9021 2024-04-09 13-15-37

Turns out packToAtlas is iterating pixel by pixel over the data and reorganizing it into a different buffer. At the innermost part of the loop, we could actually do this with a block-wise array copy rather than iterating one pixel at a time.
After this optimization, the profile shows packToAtlas consisting of a much smaller time slice!

After:

DevTools - localhost9021 2024-04-09 13-18-03

(You may notice that now onChannelLoaded is starting to dominate the time spent. However, that computation is nearly entirely eliminated by #203 .)