mobie / mobie-viewer-fiji

BSD 2-Clause "Simplified" License
28 stars 12 forks source link

Slow auto-contrast?! #1167

Closed tibuch closed 1 week ago

tibuch commented 2 weeks ago

Hi,

I am missing the time-slider in the newest version of MoBIE. I downgraded my MoBIE again and the same dataset has the time-slider. image Screenshot from the old MoBIE with the time-slider at the bottom.

This is a single-channel 3D + Time dataset.

I tried the deprecated and the newest way of opening a single ome-zarr.

tischi commented 2 weeks ago

I cannot reproduce it. I created an OME-Zarr in Fiji and opened it:

image
  new ImageJ().ui().showUI();
  final OpenImageAndLabelsCommand command = new OpenImageAndLabelsCommand();
  command.image = new File( "/Users/tischer/Desktop/tim-oliver.ome.zarr" );
  command.run();
tibuch commented 2 weeks ago

Oh, it works! But it is very slow (like 5min slow). I didn't wait long enough before and thought that nothing is happening.

I just tried again and got distracted and suddenly MoBIE opens and displays the data.

I like that the display range is set to reasonable numbers, but could this take so long?

Once MoBIE is open I can easily scroll through the data. Minimal (<1sec) load times if I access a chunk which is not cached.

tischi commented 2 weeks ago

I added some auto-contrast functionality, but depending on the how the data is stored this indeed seems to be very slow. I probably need to disable it again (at least for some data). What exactly did you load such that it was slow? Was it an HCS plate?

tibuch commented 2 weeks ago

Only a single image: .zarray:

{
    "chunks": [
        1,
        1,
        512,
        512
    ],
    "compressor": {
        "blocksize": 0,
        "clevel": 3,
        "cname": "zstd",
        "id": "blosc",
        "shuffle": 1
    },
    "dimension_separator": "/",
    "dtype": "<u2",
    "fill_value": 0,
    "filters": null,
    "order": "C",
    "shape": [
        224,
        1,
        512,
        512
    ],
    "zarr_format": 2
}

I don't know what your heuristic is, but maybe it would be sufficient to compute them only on the field of view which is displayed?

tischi commented 2 weeks ago

That means you don't have a resolution pyramid here? That would be the issue then...and yes I definitely need to restrict it to the currently visible data, that unf. is just a bit of work....but I will need to do it.

tibuch commented 2 weeks ago

Yes, there is no resolution pyramid. For this data the YX size is small enough, but time can be quite long.

tischi commented 2 weeks ago

I will release a version later today where I will disable all the auto-contrast again and then revisit this when I have a bit more time.

tischi commented 2 weeks ago

@tibuch I pushed a new version to the master branch with this modification.

Would you have time to build it and test from source and see whether that works, e.g. putting a breakpoint there and see what it does and whether it is faster now? It would be very helpful if we could debug this together....

Also I'd be very curious if the lines above are fast where I determine the number of time points and z slices, because they also already "touch" the data....

tischi commented 2 weeks ago

Hi @tibuch, the data you shared with me opens very fast. However, I am puzzled because I don't see how my recent changes should have improved this, i.e. it should have been fast before....maybe you had local network issues?

Anyway, I uploaded a new version, please test it.

tibuch commented 2 weeks ago

Should this open the AmazonS3ClientBuilder?

It is still slow for me, but I think it got a bit faster.

The drive is mounted via samba. Which is known to be "slowish", but once the data is open loading chunks is fast and before I never had this opening issue.

tibuch commented 2 weeks ago

It is super fast if I open a local copy.

tischi commented 2 weeks ago

Should this open the AmazonS3ClientBuilder?

I always initialise the AmazonS3ClientBuilder, just in case, because this can be slow, but this is running in a different thread so I would hope that it should not affect the loading of your data...but, who knows...ah, but since you are saying now that a local copy is super fast, then maybe it really is just your samba mount?

tibuch commented 2 weeks ago

Looks like it is related to the samba mount. I will try to find some time this afternoon to debug this.

Is there any directory tree parsing happening?

tischi commented 2 weeks ago

Is there any directory tree parsing happening?

Yes, probably the AmazonS3ClientBuilder is looking all over the place to find potential places where Amazon S3 Credentials could be. I already made the experience that this takes very different amounts of time on different computers.

  1. How long does this take for you? It should print it.
  2. If you have the time to run from a build from source and comment out these lines of code and see whether this speeds up things that would be very interesting!
  3. Also please try whether it makes a difference if the samba mount is present on your computer, even if you load the data from local! That would tell us whether the AmazonS3ClientBuilder is the issue.
tischi commented 2 weeks ago

And, the Janelia N5 library that I am using now to open OME-Zarr probably does quite a bit more directory parsing to open the OME-Zarr than our old code did....

tibuch commented 2 weeks ago

3. Also please try whether it makes a difference if the samba mount is present on your computer, even if you load the data from local! That would tell us whether the AmazonS3ClientBuilder is the issue.

The samba mount was present during this test this morning. The only difference was the path pointing to a local directory.

tibuch commented 2 weeks ago
  1. How long does this take for you? It should print it.

This can't be it: ( Initialised AmazonS3ClientBuilder in 963 ms. )

tischi commented 2 weeks ago

One theory: the N5 library prefetches quite some data from the OME-Zarr; it does so highly parallel, which makes it rather efficient when interacting with object stores; it may be that certain storage systems (like your samba mount and the underlying hardware) may not play well with highly parallel requests. If this turns out to be the issue we would need to get in touch with John Bogovic to see whether they tested opening OME-Zarr in such scenarios.

tischi commented 2 weeks ago

To test to above hypothesis in a cleaner way I recommend benchmarking in Fiji:

File › Import › HDF5/N5/Zarr/OME-NGFF ...

or

Plugins › BigDataViewer › HDF5/N5/Zarr/OME-NGFF Viewer

tischi commented 2 weeks ago

@tibuch please also have a look here: https://forum.image.sc/t/mobie-slow-when-saving-data/98730/5

It could be that there is something with the new N5 library that does not play well with remote file stores...

tibuch commented 2 weeks ago

Plugins › BigDataViewer › HDF5/N5/Zarr/OME-NGFF Viewer

This works instantly.

tischi commented 2 weeks ago

OK, if the above works instantly, then we have to find out which part of my code is taking all this time. Since I don't have your setup it would really be great if you could build MoBIE from source and set a few breakpoints (or use VisualVM) to see what takes so long...

tibuch commented 2 weeks ago

Current main branch of mobie-viewer-fiji should be enough?

tischi commented 2 weeks ago

Yes, main branch of mobie-viewer-fiji would be it....

But, to help debugging, I also just now added these examples to the main branch of mobie-io:

Before looking into mobie-viewer-fiji, it would be important to test within mobie-io whether

  1. The N5ViewerExample has the same performance as Plugins › BigDataViewer › HDF5/N5/Zarr/OME-NGFF Viewer
  2. The OpenOMEZarrExample has the same performance as the N5ViewerExample

If any of those differ we have something to work with. If they are all the same then I think we have to look into additional sources of slowness in mobie-viewer-fiji.


Within mobie-viewer-fiji this would be your entry point:

I was so far mainly looking into the setMetadata function of ImageGridSources in terms of finding something that could be slow; and I would also recommend this for you as a starting point...

tibuch commented 1 week ago

Good morning!

I found the issue, it is here: https://github.com/mobie/mobie-viewer-fiji/blob/59d0646a48e31e068c8410f545dda2ddba4701c4/src/main/java/org/embl/mobie/lib/MoBIEHelper.java#L338

It looks like this takes a long time once we reach the multiscale directory structure. There it parses each Timepoint, Z, and Y directory. Would it be possible to stop going deeper once a .zarray is encountered?

If I set maxDepth = 2 it works very fast. But I guess this is not a viable option.

tibuch commented 1 week ago

Maybe this requires a custom FileVisitor which uses SKIP_SUBTREE to avoid all the chunk-directories.

tischi commented 1 week ago

Great catch! I will also have a look and think about it...maybe not today, but at some point this week.

tischi commented 1 week ago

I just set the depth to 2 now (uploaded to Fiji). Honestly, I don't really know anymore for which use-cases I needed a depth > 1 at all; let's just see if that breaks anything 😅 ...

tibuch commented 1 week ago

:sweat_smile: Maybe something with detecting labelings (or other sub-groups) inside plates? I think depth 2 could lead to issues in a plate-layout, where the multiscale images start on level 5 or so.

tischi commented 1 week ago

I checked, I am using other code for that...

tischi commented 1 week ago

Can we close this?