Skip to content

Commit

Permalink
Integrate WorkerTransfer benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Aug 27, 2018
1 parent db4ef1c commit 32e0d22
Show file tree
Hide file tree
Showing 7 changed files with 15,288 additions and 9,628 deletions.
74 changes: 8 additions & 66 deletions bench/benchmarks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { OverscaledTileID } from '../../src/source/tile_id';

export default class Layout extends Benchmark {
tiles: Array<{tileID: OverscaledTileID, buffer: ArrayBuffer}>;
parser: TileParser;
style: string;
locations: Array<OverscaledTileID>;

Expand All @@ -25,87 +26,28 @@ export default class Layout extends Benchmark {
];
}

sourceID(): string {
return 'composite';
}

fetchStyle(): Promise<StyleSpecification> {
return fetch(normalizeStyleURL(this.style))
.then(response => response.json());
}

fetchTiles(styleJSON: StyleSpecification): Promise<Array<{tileID: OverscaledTileID, buffer: ArrayBuffer}>> {
const sourceURL: string = (styleJSON.sources[this.sourceID()]: any).url;
return fetch(normalizeSourceURL(sourceURL))
.then(response => response.json())
.then((tileJSON: TileJSON) => {
return Promise.all(this.locations.map(tileID => {
return fetch((normalizeTileURL(tileID.canonical.url(tileJSON.tiles))))
.then(response => response.arrayBuffer())
.then(buffer => ({tileID, buffer}));
}));
});
}

setup(): Promise<void> {
return this.fetchStyle()
return fetchStyle(this.style)
.then((styleJSON) => {
this.parser = new TileParser(styleJSON, 'composite');
return this.parser.setup();
})
.then(() => {
return Promise.all(tileIDs.map(tileID => this.parser.fetchTile(tileID)));
return Promise.all(this.locations.map(tileID => this.parser.fetchTile(tileID)));
})
.then(([style, tiles]) => {
.then((tiles) => {
this.tiles = tiles;
// parse tiles once to populate glyph/icon cache
return Promise.all(tiles.map(tile => this.parser.parseTile(tile)));
})
.then(() => {});
}

bench(getGlyphs: Function = (params, callback) => callback(null, this.glyphs[JSON.stringify(params)]),
getImages: Function = (params, callback) => callback(null, this.icons[JSON.stringify(params)])) {

const actor = {
send(action, params, callback) {
setTimeout(() => {
if (action === 'getImages') {
getImages(params, callback);
} else if (action === 'getGlyphs') {
getGlyphs(params, callback);
} else assert(false);
}, 0);
}
};

let promise: Promise<void> = Promise.resolve();

for (const {tileID, buffer} of this.tiles) {
bench() {
let promise = Promise.resolve();
for (const tile of this.tiles) {
promise = promise.then(() => {
const workerTile = new WorkerTile({
tileID: tileID,
zoom: tileID.overscaledZ,
tileSize: 512,
overscaling: 1,
showCollisionBoxes: false,
source: this.sourceID(),
uid: '0',
maxZoom: 22,
pixelRatio: 1,
request: {
url: ''
},
angle: 0,
pitch: 0,
cameraToCenterDistance: 0,
cameraToTileDistance: 0
});

const tile = new VT.VectorTile(new Protobuf(buffer));
const parse = promisify(workerTile.parse.bind(workerTile));

return parse(tile, this.layerIndex, actor);
return this.parser.parseTile(tile).then(() => {});
});
}
return promise;
Expand Down
8 changes: 7 additions & 1 deletion bench/benchmarks/worker_transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export default class WorkerTransfer extends Benchmark {
payloadTiles: Array<any>;
payloadJSON: Array<any>;
worker: Worker;
style: string;

constructor(style: string) {
super();
this.style = style;
}

setup(): Promise<void> {
const src = `
Expand All @@ -29,7 +35,7 @@ export default class WorkerTransfer extends Benchmark {
new OverscaledTileID(13, 0, 13, 2412, 3079)
];

return fetchStyle(`mapbox://styles/mapbox/streets-v9`)
return fetchStyle(this.style)
.then((styleJSON) => {
this.parser = new TileParser(styleJSON, 'composite');
return this.parser.setup();
Expand Down
Loading

0 comments on commit 32e0d22

Please sign in to comment.