saalfeldlab / paintera

GNU General Public License v2.0
99 stars 17 forks source link

Very slow painting and 2D navigation #395

Closed igorpisarev closed 4 years ago

igorpisarev commented 4 years ago

In the recent releases 0.23.x painting and 2D navigation became very slow. For some reason the 2D navigation works fine for several sources (raw+labels), but when the label source is set to invisible so that only raw data is displayed, it becomes very slow.

The call stack suggests that the FX thread spends a lot of time in this function: https://github.com/saalfeldlab/paintera/blob/master/src/main/java/org/janelia/saalfeldlab/paintera/viewer3d/OrthoSliceFX.java#L195-L215

igorpisarev commented 4 years ago

I've been working on this, and I currently have two versions of the fix: https://github.com/saalfeldlab/paintera/tree/optimize-orthoslice-textures https://github.com/saalfeldlab/paintera/tree/optimize-orthoslice-textures-background-thread

The difference is that in the first branch the texture updates are performed on FX thread which is easier and seems to perform well enough, and in the second branch the texture updates are offloaded to a background thread. These texture updates include:

The version with the background thread is supposed to perform a little better, but there's also additional overhead due to synchronization. There is also a second image buffer for the self-illumination and diffuse maps: if the currently displayed texture images are modified on a background thread, some strange visual bugs occur and eventually JavaFX starts throwing errors. To solve this I use two buffers and swap them (while one of them is displayed, another is modified by the background thread, then they are swapped).

I will do a bit more benchmarking and debugging to see which version performs better and will then merge and release.

igorpisarev commented 4 years ago

The more complicated version with the background thread performed about the same, so I went with the simpler version. Just in case it turns out that it's still slow, let's keep the branch with the background thread version for a bit: https://github.com/saalfeldlab/paintera/tree/optimize-orthoslice-textures-background-thread