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

Bucket enhancements to allow property-only update #2812

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 35 additions & 166 deletions bench/benchmarks/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,191 +4,60 @@ var VT = require('vector-tile');
var Protobuf = require('pbf');
var assert = require('assert');

var WorkerTile = require('../../js/source/worker_tile');
var Worker = require('../../js/source/worker');
var ajax = require('../../js/util/ajax');
var Style = require('../../js/style/style');
var util = require('../../js/util/util');
var ajax = require('../../js/util/ajax');
var Evented = require('../../js/util/evented');
var WorkerTile = require('../../js/source/worker_tile');
var config = require('../../js/util/config');
var coordinates = require('../lib/coordinates');
var formatNumber = require('../lib/format_number');
var runSeries = require('../lib/run_tile_series');

var SAMPLE_COUNT = 10;

module.exports = function run(options) {
config.ACCESS_TOKEN = options.accessToken;

var evented = util.extend({}, Evented);

var stylesheetURL = 'https://api.mapbox.com/styles/v1/mapbox/streets-v9?access_token=' + options.accessToken;
var evented = util.extend({}, Evented);
ajax.getJSON(stylesheetURL, function(err, stylesheet) {
if (err) return evented.fire('error', {error: err});

evented.fire('log', {
message: 'preloading assets',
color: 'dark'
});

preloadAssets(stylesheet, function(err, assets) {
if (err) return evented.fire('error', {error: err});

evented.fire('log', {
message: 'starting first test',
color: 'dark'
});

function getGlyphs(params, callback) {
callback(null, assets.glyphs[JSON.stringify(params)]);
}

function getIcons(params, callback) {
callback(null, assets.icons[JSON.stringify(params)]);
}

function getTile(url, callback) {
callback(null, assets.tiles[url]);
}

var timeSum = 0;
var timeCount = 0;

asyncTimesSeries(SAMPLE_COUNT, function(callback) {
runSample(stylesheet, getGlyphs, getIcons, getTile, function(err, time) {
if (err) return evented.fire('error', { error: err });
timeSum += time;
timeCount++;
evented.fire('log', { message: formatNumber(time) + ' ms' });
callback();
});
}, function(err) {
if (err) {
evented.fire('error', { error: err });

} else {
var timeAverage = timeSum / timeCount;
evented.fire('end', {
message: formatNumber(timeAverage) + ' ms',
score: timeAverage
});
}
});
});

return runSeries(evented, stylesheet, SAMPLE_COUNT, runTile);
});

return evented;
};

function preloadAssets(stylesheet, callback) {
var assets = {
glyphs: {},
icons: {},
tiles: {}
};

var style = new Style(stylesheet);

style.on('load', function() {
function getGlyphs(params, callback) {
style['get glyphs'](0, params, function(err, glyphs) {
assets.glyphs[JSON.stringify(params)] = glyphs;
callback(err, glyphs);
});
}

function getIcons(params, callback) {
style['get icons'](0, params, function(err, icons) {
assets.icons[JSON.stringify(params)] = icons;
callback(err, icons);
});
}

function getTile(url, callback) {
ajax.getArrayBuffer(url, function(err, response) {
assets.tiles[url] = response;
callback(err, response);
});
}

runSample(stylesheet, getGlyphs, getIcons, getTile, function(err) {
style._remove();
callback(err, assets);
});
});

style.on('error', function(event) {
callback(event.error);
function runTile (assets, coordinate, callback) {
var url = 'https://a.tiles.mapbox.com/v4/mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v6/' + coordinate.zoom + '/' + coordinate.row + '/' + coordinate.column + '.vector.pbf?access_token=' + config.ACCESS_TOKEN;

var workerTile = new WorkerTile({
coord: coordinate,
zoom: coordinate.zoom,
tileSize: 512,
overscaling: 1,
angle: 0,
pitch: 0,
showCollisionBoxes: false,
source: 'composite',
uid: url
});

}

function runSample(stylesheet, getGlyphs, getIcons, getTile, callback) {
var timeStart = performance.now();

var layerFamilies = createLayerFamilies(stylesheet.layers);

util.asyncAll(coordinates, function(coordinate, eachCallback) {
var url = 'https://a.tiles.mapbox.com/v4/mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v6/' + coordinate.zoom + '/' + coordinate.row + '/' + coordinate.column + '.vector.pbf?access_token=' + config.ACCESS_TOKEN;

var workerTile = new WorkerTile({
coord: coordinate,
zoom: coordinate.zoom,
tileSize: 512,
overscaling: 1,
angle: 0,
pitch: 0,
showCollisionBoxes: false,
source: 'composite',
uid: url
});

var actor = {
send: function(action, params, sendCallback) {
setTimeout(function() {
if (action === 'get icons') {
getIcons(params, sendCallback);
} else if (action === 'get glyphs') {
getGlyphs(params, sendCallback);
} else assert(false);
}, 0);
}
};
var actor = {
send: function(action, params, sendCallback) {
setTimeout(function() {
if (action === 'get icons') {
assets.getIcons(params, sendCallback);
} else if (action === 'get glyphs') {
assets.getGlyphs(params, sendCallback);
} else assert(false);
}, 0);
}
};

getTile(url, function(err, response) {
if (err) throw err;
var data = new VT.VectorTile(new Protobuf(response));
workerTile.parse(data, layerFamilies, actor, function(err) {
if (err) return callback(err);
eachCallback();
});
assets.getTile(url, function(err, response) {
if (err) throw err;
var data = new VT.VectorTile(new Protobuf(response));
workerTile.parse(data, assets.layerFamilies, actor, function(err) {
if (err) return callback(err);
callback();
});
}, function(err) {
var timeEnd = performance.now();
callback(err, timeEnd - timeStart);
});
}

function asyncTimesSeries(times, work, callback) {
if (times > 0) {
work(function(err) {
if (err) callback(err);
else asyncTimesSeries(times - 1, work, callback);
});
} else {
callback();
}
}

var createLayerFamiliesCacheKey;
var createLayerFamiliesCacheValue;
function createLayerFamilies(layers) {
if (layers !== createLayerFamiliesCacheKey) {
var worker = new Worker({addEventListener: function() {} });
worker['set layers'](0, layers);

createLayerFamiliesCacheKey = layers;
createLayerFamiliesCacheValue = worker.layerFamilies[0];
}
return createLayerFamiliesCacheValue;
}
74 changes: 74 additions & 0 deletions bench/benchmarks/dds_parse_bucket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

var VT = require('vector-tile');
var Protobuf = require('pbf');
var assert = require('assert');

var util = require('../../js/util/util');
var ajax = require('../../js/util/ajax');
var Evented = require('../../js/util/evented');
var WorkerTile = require('../../js/source/worker_tile');
var config = require('../../js/util/config');
var runSeries = require('../lib/run_tile_series');

var SAMPLE_COUNT = 10;

module.exports = function run(options) {
config.ACCESS_TOKEN = options.accessToken;
var stylesheetURL = 'https://api.mapbox.com/styles/v1/mapbox/streets-v9?access_token=' + options.accessToken;
var evented = util.extend({}, Evented);
ajax.getJSON(stylesheetURL, function(err, stylesheet) {
if (err) return evented.fire('error', {error: err});

stylesheet.layers.forEach(function (layer) {
if (layer.type === 'fill' && layer.paint) {
layer.paint['fill-color'] = {
property: 'level',
stops: [[0, 'white'], [100, 'blue']]
};
}
});

return runSeries(evented, stylesheet, SAMPLE_COUNT, runTile);
});

return evented;
};

function runTile (assets, coordinate, callback) {
var url = 'https://a.tiles.mapbox.com/v4/mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v6/' + coordinate.zoom + '/' + coordinate.row + '/' + coordinate.column + '.vector.pbf?access_token=' + config.ACCESS_TOKEN;

var workerTile = new WorkerTile({
coord: coordinate,
zoom: coordinate.zoom,
tileSize: 512,
overscaling: 1,
angle: 0,
pitch: 0,
showCollisionBoxes: false,
source: 'composite',
uid: url
});

var actor = {
send: function(action, params, sendCallback) {
setTimeout(function() {
if (action === 'get icons') {
assets.getIcons(params, sendCallback);
} else if (action === 'get glyphs') {
assets.getGlyphs(params, sendCallback);
} else assert(false);
}, 0);
}
};

assets.getTile(url, function(err, response) {
if (err) throw err;
var data = new VT.VectorTile(new Protobuf(response));
workerTile.parse(data, assets.layerFamilies, actor, function(err) {
if (err) return callback(err);
callback();
});
});
}

Loading