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

Option to run force simulations on a Web Worker #2996

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

wmurphyrd
Copy link

@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 of simulation (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

@lgtm-com
Copy link

lgtm-com bot commented Dec 9, 2020

This pull request introduces 1 alert when merging e097768 into d2ceffa - view on LGTM.com

new alerts:

  • 1 for Superfluous trailing arguments

@domoritz domoritz requested a review from jheer December 10, 2020 14:35
@wmurphyrd
Copy link
Author

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 worker transform option could be a simple Boolean and it would work from CDN, I'd be happy to implement, but I wanted to check first since it's non-standard.

@kanitw kanitw requested a review from a team as a code owner May 20, 2024 23:33
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.

None yet

2 participants