-
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
Add a minimal global worker pool #2952
Conversation
Rebasing, previous at d3d0787 |
d3d0787
to
328991d
Compare
FWIW: I'm using this branch in a project where we have multiple maps on a page, and even just having a shared pool--without actually deduping any of the work--significantly reduces the initial load time, because initializing each Worker is a pretty significant overhead. |
Updated top of ticket with rationale and the checklist from the new PR template |
94dfd96
to
afbdafd
Compare
Rebased, with previous head = 94dfd96 |
Wouldn't expect these changes to affect the benchmarks much, but that's partly the point of them, right? This branchbuffer: 886 ms MasterBroke w/ console errors at the end of query-point, but here are the first buffer: 868 ms |
Added a benchmark to measure the time from masterload-multiple-maps: 7,024 ms, loaded 6 maps. This branchload-multiple-maps: 4,778 ms, loaded 6 maps. |
Add a minimal global worker pool
Add a minimal global worker pool
Add a minimal global worker pool
Add a minimal global worker pool
Add a minimal global worker pool
In light of a global worker pool, I don't know that either of the following seem necessary/useful: (a) having different map instances use a different number of workers, or (b) being able to resize the worker pool. Does it make sense to remove the |
Makes sense. I would go for something like |
I think it could be set by a user who was tying to balance a GL JS map versus other cpu-intensive stuff in a web app. (For instance: in a project we're working on, I was thinking of intentionally limiting the GL JS worker count to 3/4 of the available workers, so that 1/4 could be dedicated to keeping some other expensive data-munging off the main thread to keep the UI snappier) |
^ but, with that said, I don't actually have any objections to making it a constant like you proposed, @mourner |
Add a minimal global worker pool
Add a minimal global worker pool
Actually, just a note that making this a constant on the |
bf19632
to
f21dced
Compare
Add a minimal global worker pool
Add a minimal global worker pool # Conflicts: # test/js/style/style.test.js
Went with (note: also rebased to master) |
Add a minimal global worker pool # Conflicts: # js/source/worker.js # test/js/style/style.test.js
|
||
return evented; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written, this benchmark is highly dependent on the tester's network speed. Can you think of a way to remove that dependency? What are we testing in this benchmark that isn't captured by the buffer
benchmark?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. My intent in this benchmark was to measure the impact of sending all the worker code to each of the worker threads on the map load time. We can eliminate any outside network use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the benchmark to use an empty style, so it should now not depend at all on network speed
This is ready to merge on 🍏 . Just rebased to include #3043. |
Whoops, will also need #3052 to get a :green: here. Once that's merged I'll rebase again and then (hopefully) merge |
This is still not great, but it's better than having it in Dispatcher. Ultimately the right place to put it is at the root level, i.e. mapbox-gl.js, and then pass it through, but that will be a noisy change due the number of 'new Map()' and 'new Style()' in the unit tests
The previous commit (2f00368) broke the webpack test due to webpack/webpack#300. This changes the webpack config so that mapbox-gl itself is not the entrypoint.
Rebasing -- previous at 84ce97b |
84ce97b
to
ea12906
Compare
Success! Merging. |
Ack - just realized that I dropped the ball on this comment -- the diff changed while I was addressing something else, and so I forgot about it. @lucaswoj if I don't get a chance to open a PR patching that today, I'll file an issue so it doesn't get lost |
@anandthakker It's a minor change, don't stress over it. |
Closes #899
@lucaswoj this is a much more focused / less ambitious change than #2917. It adds a global worker pool, making only the minimal changes necessary to allow a Worker to serve multiple map instances correctly.
It does not attempt to deduplicate the work that is done for different map instances. Nonetheless, there are benefits to sharing workers. Immediate benefit: the overhead to create a worker is significant, because it essentially involves copying all of the worker code over from the main thread. Future benefit: using shared workers paves the way for more ambitious performance inter-map-instance improvements like #2951
Specific Notes
Worker#layers
, andWorker#layerFamilies
into objects keyed off ofmapId
.WorkerSource
instance for each source type. Now, when a WorkerSource is registered, we just hold on to the class, and instantiate a separate one for each map (or rather, for eachmapId
). Doing it this way means that none of the code in GeoJSONWorkerSource or VectorTileWorkerSource had to be touched.workerCount
Map option is removed in favor ofmapboxgl.WorkerPool.WORKER_COUNT
Checklist
Dispatcher
correctly consumesWorkerPool
WorkerPool
Actor
s using the same underlyingWorker
.master