-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Option to run force simulations on a Web Worker #2996
base: main
Are you sure you want to change the base?
Conversation
…ild enytrpoint for worker script
…der to discard results relating to obsolete data
…ing initial transform
This pull request introduces 1 alert when merging e097768 into d2ceffa - view on LGTM.com new alerts:
|
Re the worker script URL requirement, there are workarounds, but they mostly involve unsafe inline code evaluation and may not have universal browser support. If you'd prefer this route, such that the |
@jheer we talked about this on Slack when I first began the project and there was potential interest in merging to main. We've been using this in production for several months, but I've just now had a chance to upgrade and confirm it works with the current Vega version.
This adds a worker option to the force transform which will cause simulation calculations to be performed in a Web Worker thread. This improves the user experience when running sims on large datasets because it avoids threadlocking the browser.
I've added a
simulationWorker
that mimics the existing api ofsimulation
(to minimize changes to existing code), but coordinates messaging with the worker thread to offload the work there.Due to browser security policies surrounding Web Workers, they must be instantiated with a URL to a script for the worker source that obeys a strict same-origin policy, the use cases for the worker mode are limited compared to Vega in general. The built worker thread file,
vega-force.worker.js
cannot be sourced from CDN, so users will have to host and serve the file. However, the transform continues to work on the main thread without changes if the worker mode is not set in the transform settings.Here's a live demo: https://glitch.com/edit/#!/vega-force-worker?path=index.html%3A1%3A1