-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a minimal global worker pool (#2952)
* Enable Worker to do work for multiple map instances * Add minimal worker pool * Include mapId in Actors' callback tracking * Unit test Dispatcher's use of WorkerPool * Fix benchmark * Add WorkerPool unit tests * Add a unit test for 2 Actors using the same Worker * Fix parameter in Worker 'redo placement' test * Add map load benchmark * Move the static worker pool instance to style.js 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 * Use a fixed worker pool size * Use empty style in load-multiple-maps benchmark * Drop shared_workers debug in favor of multiple.html * WorkerPool.WORKER_COUNT => mapboxgl.workerCount * Fix webpack build test 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. * Use more descriptive parameter name, mapId * Rename layers => layerDefinitions, styleLayers => layers * Remove mapboxgl.WorkerPool
- Loading branch information
1 parent
6eb4b0a
commit 072f8cd
Showing
21 changed files
with
440 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
var Evented = require('../../js/util/evented'); | ||
var util = require('../../js/util/util'); | ||
var formatNumber = require('../lib/format_number'); | ||
|
||
module.exports = function(options) { | ||
var evented = util.extend({}, Evented); | ||
|
||
var mapsOnPage = 6; | ||
|
||
evented.fire('log', { message: 'Creating ' + mapsOnPage + ' maps' }); | ||
|
||
var loaded = 0; | ||
var start = Date.now(); | ||
for (var i = 0; i < mapsOnPage; i++) { | ||
var map = options.createMap({ | ||
style: { | ||
version: 8, | ||
sources: {}, | ||
layers: [] | ||
} | ||
}); | ||
map.on('load', onload.bind(null, map)); | ||
map.on('error', function (err) { | ||
evented.fire('error', err); | ||
}); | ||
} | ||
|
||
function onload () { | ||
if (++loaded >= mapsOnPage) { | ||
var duration = Date.now() - start; | ||
evented.fire('end', { | ||
message: formatNumber(duration) + ' ms, loaded ' + mapsOnPage + ' maps.', | ||
score: duration | ||
}); | ||
done(); | ||
} | ||
} | ||
|
||
function done () { | ||
} | ||
|
||
return evented; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
var WorkerPool = require('./util/worker_pool'); | ||
|
||
var globalWorkerPool; | ||
|
||
/** | ||
* Creates (if necessary) and returns the single, global WorkerPool instance | ||
* to be shared across each Map | ||
* @private | ||
*/ | ||
module.exports = function getGlobalWorkerPool () { | ||
if (!globalWorkerPool) { | ||
globalWorkerPool = new WorkerPool(); | ||
} | ||
return globalWorkerPool; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.