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

[ui] Thumbnail cache #1861

Merged
merged 29 commits into from
Feb 9, 2023
Merged

[ui] Thumbnail cache #1861

merged 29 commits into from
Feb 9, 2023

Conversation

mugulmd
Copy link
Contributor

@mugulmd mugulmd commented Jan 5, 2023

Description

This PR introduces a new caching mechanism for thumbnails to improve interactivity when navigating in the Image Gallery.

This cache associates to each image a unique thumbnail, which is stored on disk for later reuse.

Cache directory

The storing location is global (i.e not specific to a Meshroom scene).
The default location can be overriden with the MESHROOM_THUMBNAIL_DIR environment variable.

The thumbnails dimensions cannot exceed 256x256, and are stored on disk in JPEG format.
On the tested dataset, their size vary between 6 and 11 Ko (per thumbnail).

Automatic cleaning process

When launching the application, the cache directory is scanned and all thumbnails that haven't been used for more than a certain time limit are removed. This process also makes sure that the number of thumbnails on disk does not exceed a certain limit.

The default time limit is 90 days, and can be overriden with the MESHROOM_THUMBNAIL_TIME_LIMIT environment variable.

The default maximum number of thumbnails on disk is 100000, and can be overriden with the MESHROOM_MAX_THUMBNAILS_ON_DISK environment variable.

Asynchronous thumbnail creation

Since thumbnail creation can be quite long on large image datasets it is performed asynchronously (using 3 worker threads) to avoid blocking the UI.
A loading circle is displayed during the thumbnail creation process to let the user know that computations are undergoing.

When a thumbnail is created, a signal is sent to the Image Gallery, and the grid view is in charge of dispatching it to the corresponding Image Delegate.

Details on thumbnail creation requests

Thumbnail creation requests are stored in a LIFO (last-in-first-out) structure: this way, when scrolling through the image gallery, the items that the user is currently viewing have priority in the calculations.

Also, to avoid situations in which thumbnails are never retrieved, a timer is used to re-send some requests every 2 seconds if needed.

Finally, all requests are cleared when the viewpoints change. This way, when changing the scene, if thumbnail calculations of the previous scene are not finished (which can happen if the image dataset is quite large), they won't slow done calculations of the current scene.

Tests

Tested on Windows and Linux, using images with different formats (JPEG, EXR, RAW), aspect ratio and Exif orientation tags.

Tested varying the storage time limit and maximum number of thumbnails on disk.

Tested with existing and non-existing thumbnail directory (in the second case, the directory is created recursively).

Stress tested on a 12000 high resolution images dataset and compared to current develop branch to check that fluidity has improved.

@mugulmd mugulmd self-assigned this Jan 5, 2023
@mugulmd mugulmd marked this pull request as ready for review January 6, 2023 10:27
@mugulmd mugulmd requested a review from mh0g January 6, 2023 15:21
@mh0g
Copy link
Contributor

mh0g commented Jan 6, 2023

Tested loading on windows with jpg datasets from 16 to 1000 images, loading seems to work.
After saving and loading the project, doing a clear image freezes

@mugulmd
Copy link
Contributor Author

mugulmd commented Jan 6, 2023

Tested loading on windows with jpg datasets from 16 to 1000 images, loading seems to work. After saving and loading the project, doing a clear image freezes

After some investigation it seems that this is not related to this PR.

More specifically the problem is that for large image datasets (noticed on datasets with 1000 images) the "Clear Image" action will freeze the app.

@mugulmd
Copy link
Contributor Author

mugulmd commented Jan 6, 2023

Remark:
When loading images that do not have a thumbnail, the app blocks while the thumbnails are being computed.
It would be nice to have at least a loading icon.

@mugulmd
Copy link
Contributor Author

mugulmd commented Jan 9, 2023

Remark: When loading images that do not have a thumbnail, the app blocks while the thumbnails are being computed. It would be nice to have at least a loading icon.

Actually now thumbnail creation is asynchronous so the app doesn't block.

Copy link
Member

@fabiencastan fabiencastan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to change default path for meshroom cache and some minor improvements.

@fabiencastan fabiencastan added this to the Meshroom 2023.1.0 milestone Jan 20, 2023
meshroom/ui/components/thumbnail.py Outdated Show resolved Hide resolved
@fabiencastan fabiencastan marked this pull request as draft January 22, 2023 19:00
@mugulmd mugulmd marked this pull request as ready for review January 23, 2023 16:28
mugulmd and others added 4 commits January 26, 2023 05:10
As we rely on the thumbnails cache, the images are already downscaled at
a small resolution. So there is no more need to force a max resolution
on the Qml Image.
@fabiencastan fabiencastan merged commit 334bfc8 into develop Feb 9, 2023
@fabiencastan fabiencastan deleted the mug/thumbnailCache branch February 9, 2023 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants