Skip to content

Avoid duplicated opencv/ort fetches#6494

Open
jpggvilaca wants to merge 2 commits into
developfrom
jvilaca/improve-wasm-assets-loading
Open

Avoid duplicated opencv/ort fetches#6494
jpggvilaca wants to merge 2 commits into
developfrom
jvilaca/improve-wasm-assets-loading

Conversation

@jpggvilaca
Copy link
Copy Markdown
Contributor

Summary

  • Also improves worker termination (We only terminate the workers once we leave the dataset page)

Explanation:
onnx spawns X workers, where X depends on the amount of cpu cores your machine has, and each worker imports ort, hence why we would see all these imports. Same goes for opencv. We could limit the threads but concurrency is what we want, so we have a tradeoff between bandwith/memory and performance.

Before:
Screenshot 2026-05-15 at 14 52 27
Screenshot 2026-05-15 at 14 52 34

After:
Screenshot 2026-05-15 at 14 51 59
Screenshot 2026-05-15 at 14 52 05

How to test

Checklist

  • The PR title and description are clear and descriptive
  • I have manually tested the changes
  • All changes are covered by automated tests
  • All related issues are linked to this PR (if applicable)
  • Documentation has been updated (if applicable)

Copilot AI review requested due to automatic review settings May 15, 2026 13:18
@jpggvilaca jpggvilaca requested a review from a team as a code owner May 15, 2026 13:18
@jpggvilaca jpggvilaca added the Geti UI Issues related to Geti application frontend label May 15, 2026
// before build/init resolve, so we don't leak the in-flight worker.
signal.addEventListener('abort', worker.terminate, { once: true });
//
// CRITICAL: pass an arrow function, NOT `worker.terminate` directly.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is the fix for the duplication.

headers: {
'Cross-Origin-Embedder-Policy': 'credentialless',
'Cross-Origin-Opener-Policy': 'same-origin',
'Cache-Control': 'public, max-age=31536000, immutable',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this should be done in production (already asked backend) but it also improves DX. Basically it tells the browser that these files will never change (opencv, wasm, etc) so it's all good to cache them, even if hashed (e.g. ort23478234823.wasm)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts annotator web-worker lifecycle management to avoid repeated ORT/OpenCV/model fetches by keeping workers alive across intra-dataset navigation and terminating them only when leaving the dataset section.

Changes:

  • Move annotator-tool worker teardown from annotator unmount to the dataset-section boundary via a new useTerminateAnnotatorWorkersOnUnmount hook.
  • Keep the Segment Anything worker query alive indefinitely (gcTime: Infinity) and fix its abort handler to reliably terminate on cancellation.
  • Add a global Cache-Control header in the Rsbuild dev server config.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
application/ui/src/router.tsx Introduces DatasetSection wrapper to own worker lifetime across dataset routes.
application/ui/src/features/annotator/tools/use-preload-webworkers.hook.ts Removes per-annotator unmount teardown so workers can persist within the dataset section.
application/ui/src/features/annotator/tools/terminate-annotator-workers-on-unmount.hook.ts Adds dataset-section unmount cleanup to terminate workers and remove worker queries.
application/ui/src/features/annotator/tools/segment-anything-tool/use-segment-anything.hook.ts Improves worker caching and abort termination behavior; sets gcTime: Infinity.
application/ui/rsbuild.config.ts Adds a global Cache-Control response header for the dev server.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread application/ui/src/router.tsx
Comment thread application/ui/rsbuild.config.ts
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 15, 2026

🐳 Docker image sizes

Device Size
xpu 10578.6 MB (10.33 GB)
cuda 9783.2 MB (9.55 GB)
cpu 3588.0 MB (3.50 GB)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 15, 2026

📊 Test coverage report

Metric Coverage
Lines 59.8%
Functions 80.7%
Branches 88.0%
Statements 59.8%

// for no functional gain (encoder/decoder always run sequentially anyway).
//
// `gcTime: Infinity` is critical: the default 5-min gc would evict the worker
// entry whenever SAM is unmounted (switching tools/projects), causing the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unmounted and not used for 5 min I guess, not right away after unmunting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Geti UI Issues related to Geti application frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants