Skip to content

Commit

Permalink
Add benchmark that specifically targets performSymbolLayout (e.g. t…
Browse files Browse the repository at this point in the history
…ext shaping and line breaking)

Use style_locations as input to ensure CJK-dense tiles are tested.
  • Loading branch information
ChrisLoer committed Oct 5, 2018
1 parent 4d86572 commit 8e57c1d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 6 deletions.
47 changes: 47 additions & 0 deletions bench/benchmarks/symbol_layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// @flow

import Layout from './layout';
import SymbolBucket from '../../src/data/bucket/symbol_bucket';
import { performSymbolLayout } from '../../src/symbol/symbol_layout';
import { OverscaledTileID } from '../../src/source/tile_id';

export default class SymbolLayout extends Layout {
parsedTiles: Array<any>;

constructor(style: string, locations: ?Array<OverscaledTileID>) {
super(style, locations);
this.parsedTiles = [];
}

setup(): Promise<void> {
return super.setup().then(() => {
// Do initial load/parse of tiles and hold onto all the glyph/icon
// dependencies so that we can re-do symbol layout in isolation
// during the bench step.
return Promise.all(this.tiles.map(tile =>
this.parser.parseTile(tile, true).then((tileResult) => {
this.parsedTiles.push(tileResult);
})
)).then(() => {});
});
}

bench() {
let promise = Promise.resolve();
for (const tileResult of this.parsedTiles) {
promise = promise.then(() => {
for (const bucket of tileResult.buckets) {
if (bucket instanceof SymbolBucket) {
performSymbolLayout(bucket,
tileResult.glyphMap,
tileResult.glyphPositions,
tileResult.iconMap,
tileResult.imageAtlas.iconPositions,
false);
}
}
});
}
return promise;
}
}
5 changes: 3 additions & 2 deletions bench/lib/tile_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class TileParser {
.then(buffer => ({tileID, buffer}));
}

parseTile(tile: {tileID: OverscaledTileID, buffer: ArrayBuffer}): Promise<?WorkerTileResult> {
parseTile(tile: {tileID: OverscaledTileID, buffer: ArrayBuffer}, returnDependencies?: boolean): Promise<?WorkerTileResult> {
const workerTile = new WorkerTile({
tileID: tile.tileID,
zoom: tile.tileID.overscaledZ,
Expand All @@ -123,7 +123,8 @@ export default class TileParser {
angle: 0,
pitch: 0,
cameraToCenterDistance: 0,
cameraToTileDistance: 0
cameraToTileDistance: 0,
returnDependencies: returnDependencies
});

const vectorTile = new VT.VectorTile(new Protobuf(tile.buffer));
Expand Down
3 changes: 3 additions & 0 deletions bench/versions/benchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mapboxgl from '../../src';
import accessToken from '../lib/access_token';
import { summaryStatistics, regression } from '../lib/statistics';
import updateUI from '../benchmarks_view';
import styleLocations from '../lib/style_locations';

mapboxgl.accessToken = accessToken;

Expand All @@ -17,6 +18,7 @@ function register(benchmark) {

import Layout from '../benchmarks/layout';
import LayoutDDS from '../benchmarks/layout_dds';
import SymbolLayout from '../benchmarks/symbol_layout';
import WorkerTransfer from '../benchmarks/worker_transfer';
import Paint from '../benchmarks/paint';
import PaintStates from '../benchmarks/paint_states';
Expand Down Expand Up @@ -47,6 +49,7 @@ register(new PaintStates(center));
LayerBenchmarks.forEach((Bench) => register(new Bench()));
register(new Load());
register(new LayoutDDS());
register(new SymbolLayout(style, styleLocations.map(location => location.tileID[0])));
register(new FilterCreate());
register(new FilterEvaluate());

Expand Down
4 changes: 3 additions & 1 deletion src/render/glyph_atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export type GlyphPosition = {
metrics: GlyphMetrics
};

export type GlyphPositions = { [string]: { [number]: GlyphPosition } }

export default class GlyphAtlas {
image: AlphaImage;
positions: { [string]: { [number]: GlyphPosition } };
positions: GlyphPositions;

constructor(stacks: { [string]: { [number]: ?StyleGlyph } }) {
const positions = {};
Expand Down
12 changes: 10 additions & 2 deletions src/source/worker_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import type {RequestParameters} from '../util/ajax';
import type {RGBAImage, AlphaImage} from '../util/image';
import type { GlyphPositions } from '../render/glyph_atlas';
import type ImageAtlas from '../render/image_atlas';
import type {OverscaledTileID} from './tile_id';
import type {Bucket} from '../data/bucket';
import type FeatureIndex from '../data/feature_index';
import type {CollisionBoxArray} from '../data/array_types';
import type DEMData from '../data/dem_data';
import type {PerformanceResourceTiming} from '../types/performance_resource_timing';
import type { StyleGlyph } from '../style/style_glyph';
import type { StyleImage } from '../style/style_image';

export type TileParameters = {
source: string,
Expand All @@ -23,7 +26,8 @@ export type WorkerTileParameters = TileParameters & {
tileSize: number,
pixelRatio: number,
showCollisionBoxes: boolean,
collectResourceTiming?: boolean
collectResourceTiming?: boolean,
returnDependencies?: boolean
};

export type WorkerDEMTileParameters = TileParameters & {
Expand All @@ -39,7 +43,11 @@ export type WorkerTileResult = {
featureIndex: FeatureIndex,
collisionBoxArray: CollisionBoxArray,
rawTileData?: ArrayBuffer,
resourceTiming?: Array<PerformanceResourceTiming>
resourceTiming?: Array<PerformanceResourceTiming>,
// Only used for benchmarking:
glyphMap?: {[string]: {[number]: ?StyleGlyph}} | null,
iconMap?: {[string]: StyleImage} | null,
glyphPositions?: GlyphPositions | null
};

export type WorkerTileCallback = (error: ?Error, result: ?WorkerTileResult) => void;
Expand Down
8 changes: 7 additions & 1 deletion src/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class WorkerTile {
overscaling: number;
showCollisionBoxes: boolean;
collectResourceTiming: boolean;
returnDependencies: boolean;

status: 'parsing' | 'done';
data: VectorTile;
Expand All @@ -56,6 +57,7 @@ class WorkerTile {
this.overscaling = this.tileID.overscaleFactor();
this.showCollisionBoxes = params.showCollisionBoxes;
this.collectResourceTiming = !!params.collectResourceTiming;
this.returnDependencies = !!params.returnDependencies;
}

parse(data: VectorTile, layerIndex: StyleLayerIndex, actor: Actor, callback: WorkerTileCallback) {
Expand Down Expand Up @@ -196,7 +198,11 @@ class WorkerTile {
featureIndex,
collisionBoxArray: this.collisionBoxArray,
glyphAtlasImage: glyphAtlas.image,
imageAtlas: imageAtlas
imageAtlas: imageAtlas,
// Only used for benchmarking:
glyphMap: this.returnDependencies ? glyphMap : null,
iconMap: this.returnDependencies ? iconMap : null,
glyphPositions: this.returnDependencies ? glyphAtlas.positions : null
});
}
}
Expand Down

0 comments on commit 8e57c1d

Please sign in to comment.