-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Create a global worker pool #899
Comments
Not sure how much this matters. If web workers are implemented as green threads then it may not. |
@jfirebaugh I'd like to be able to control the number of workers that mapbox-gl uses -- I'm envisioning using it in an app that also has some other heavy lifting to do, so that I might want to use a couple workers of my own. As you point out, this is less of an issue if browsers implement web workers are green threads, but it could still be useful to be able to tune it. |
Another, perhaps much more important, reason that this could matter: if there are multiple maps on the same page that use the same sources, there could be a lot of redundant parsing/processing of the same vector tile data. A worker pool shared among |
@jfirebaugh @lucaswoj would you be open to a PR to address this? |
@anandthakker we're always open to PRs :) |
@mourner Hah! I guess what I really mean to ask is: this would definitely add a bit of complexity, and perhaps it has other drawbacks that I haven't thought of. Given that, do you all feel that the benefits for this change would be worth the added complexity? |
@anandthakker depends on the amount of added complexity, which is hard to judge before I see a PR. :) But you could outline the approach you'd like to take first before writing any code. |
Here is what I am thinking:
{
forEach: (fn: (Actor) => void) => void,
getActor: (id) => Actor // with 'id' now a property of Actor instances, managed by the pool
getCurrentActor: () => Actor
}
|
Questions:
I guess a way to do this is to have ActorPool as follows: {
requestActors: (numActors: number) => token,
releaseActors: (token) => void,
forEach: (fn: (Actor) => void) => void,
getActor: (id) => Actor // with 'id' now a property of Actor instances, managed by the pool
getCurrentActor: () => Actor
} |
Another issue: workers also have a This would require a way to identify each style instance that's in use; e.g.: The actual mapbox style ID probably doesn't work, since the style can be given as JSON; maybe a hash of the serialized style? Alternatively, and simpler, the |
I support any interface that makes the workers stateless (or, at least, appear to be stateless to their callers) |
mapbox-gl-js should use
navigator.hardwareConcurrency - 1
workers no matter how many maps are on a page or how many times you callmap.setStyle()
.The text was updated successfully, but these errors were encountered: