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] Drag&Drop: Use a pool of threads for asynchronous intrinsics computations #1896

Merged
merged 2 commits into from
Feb 14, 2023

Conversation

cbentejac
Copy link
Contributor

Description

This PR fixes an issue that occurred when dragging and dropping images from a folder into Meshroom's Image Gallery.

When dropping new images, the intrinsics were rebuilt asynchronously in a thread that was not attached to anything. The update of the intrinsics, performed in the main thead following a signal emitted in the detached thread, would block when there were already some existing intrinsics (and thus already some existing images in the gallery) because the garbage collector would destroy the thread in which the new intrinsics had been computed while the update was ongoing. It seems the issue did not appear when there was not any image in the gallery because the update of the intrinsics did not need to remove the previously existing ones before adding the new ones.

  • This pull request adds a pool of threads (currently, the pool contains a single thread as the intrinsics computation is the only operation that needs to be performed asynchronously) to the Reconstruction object and uses it to perform the intrinsics computations asynchronously. As a consequence, the update of the intrinsics does not remain blocked and images can be dragged and dropped in the Image Gallery safely.

  • Additionally, importing images through the "Import Images" menu action is now performed asynchronously as well. It used to be synchronous, and as such, not subject to the update issue, but as it was both a blocking and costly operations, it would freeze the application entirely until it was completed. "Import Images" now uses the same workflow as dragging and dropping images.

Features list

  • Execute "Import Images" asynchronously to avoid freezing the application
  • Use a pool of threads instead of a detached thread to perform asynchronous operations

Implementation remarks

  • The "Update Intrinsics" button, which appears when the dialog to edit the sensor database is on display and caused the same issue as the drag and drop, now also uses the pool of threads to recompute the intrinsics when requested
  • The "runAsync" method, which spawned a thread without attaching it to anything, is removed.
  • The "importImagesAsync" method, whose only goal was to call "runAsync" on "importImagesSync", is also removed. Instead, the pool of threads is directly used to call "importImagesSync" asynchronously.

Loading images with the "Import Images" menu action is a blocking
operation that might freeze the app if there are many images to import.

This commit performs the import asynchronously (similarly to what is done
when images are dropped in the Image Gallery): Meshroom remains unusable
while the images are imported and the intrinsics built (which is a wanted
behaviour), but it does not freeze at all.
When importing images, the intrinsics were (re)built asynchronously in
a thread that was not attached to anything. The update of the intrinsics,
performed in the main thread following a signal emitted in the detached
thread, would block when there were already some existing intrinsics
because the garbage collector would destroy the thread in which the
new intrinsics had been computed while the update was ongoing.

This commit adds a ThreadPool to the Reconstruction object, and uses it
to perform the intrinsics computations asynchronously. The update of the
intrinsics thus does not remain blocked and images can be imported safely,
either though the "Import Images" menu or through drag & drop.

The "Update Intrinsics" button, which appears when the dialog to edit the
sensor database is on display, also uses the ThreadPool to recompute the
intrinsics when requested.

The "runAsync" method, which spawned a thread without attaching it to
anything, is removed. The "importImagesAsync" method, whose only goal
was to call "runAsync" on "importImagesSync", is also removed. Instead,
the pool of threads is directly used to call "importImagesSync"
asynchronously.
@cbentejac cbentejac self-assigned this Feb 14, 2023
@fabiencastan fabiencastan added this to the Meshroom 2023.1.0 milestone Feb 14, 2023
@fabiencastan fabiencastan merged commit 1fc2b22 into develop Feb 14, 2023
@fabiencastan fabiencastan deleted the fix/dragDropImages branch February 14, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants