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

Add placementTime metric #11043

Merged
merged 5 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/style/pauseable_placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import browser from '../util/browser.js';

import {Placement} from '../symbol/placement.js';
import {PerformanceUtils} from '../util/performance.js';

import type Transform from '../geo/transform.js';
import type StyleLayer from './style_layer.js';
Expand All @@ -11,6 +12,8 @@ import type Tile from '../source/tile.js';
import type {BucketPart} from '../symbol/placement.js';
import type {FogState} from './fog_helpers.js';

let placementId = 1;

class LayerPlacement {
_sortAcrossTiles: boolean;
_currentTileIndex: number;
Expand All @@ -29,7 +32,6 @@ class LayerPlacement {
}

continuePlacement(tiles: Array<Tile>, placement: Placement, showCollisionBoxes: boolean, styleLayer: StyleLayer, shouldPausePlacement: () => boolean) {

const bucketParts = this._bucketParts;

while (this._currentTileIndex < tiles.length) {
Expand Down Expand Up @@ -61,6 +63,7 @@ class LayerPlacement {

class PauseablePlacement {
placement: Placement;
_id: number;
_done: boolean;
_currentPlacementIndex: number;
_forceFullPlacement: boolean;
Expand All @@ -80,6 +83,7 @@ class PauseablePlacement {
this._forceFullPlacement = forceFullPlacement;
this._showCollisionBoxes = showCollisionBoxes;
this._done = false;
this._id = placementId++;
}

isDone(): boolean {
Expand Down Expand Up @@ -109,6 +113,7 @@ class PauseablePlacement {
const pausePlacement = this._inProgressLayer.continuePlacement(layerTiles[layer.source], this.placement, this._showCollisionBoxes, layer, shouldPausePlacement);

if (pausePlacement) {
PerformanceUtils.recordPlacementTime(this._id, browser.now() - startTime);
// We didn't finish placing all layers within 2ms,
// but we can keep rendering with a partial placement
// We'll resume here on the next frame
Expand All @@ -120,7 +125,7 @@ class PauseablePlacement {

this._currentPlacementIndex--;
}

PerformanceUtils.recordPlacementTime(this._id, browser.now() - startTime);
this._done = true;
}

Expand Down
34 changes: 33 additions & 1 deletion src/util/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export type PerformanceMetrics = {
workerInitialization: number,
workerEvaluateScript: number,
workerIdle: number,
workerIdlePercent: number
workerIdlePercent: number,
placementTime: number
};

export const PerformanceMarkers = {
Expand All @@ -27,7 +28,9 @@ export const PerformanceMarkers = {
};

let lastFrameTime = null;
let fullLoadFinished = false;
let frameTimes = [];
let placementTimes = {};
const frameSequences = [frameTimes];
let i = 0;

Expand All @@ -45,6 +48,10 @@ const frameTimeTarget = 1000 / framerateTarget;
export const PerformanceUtils = {
mark(marker: $Keys<typeof PerformanceMarkers>) {
performance.mark(marker);

if (marker === PerformanceMarkers.fullLoad) {
fullLoadFinished = true;
}
},
measure(name: string, begin?: string, end?: string) {
performance.measure(name, begin, end);
Expand All @@ -60,7 +67,23 @@ export const PerformanceUtils = {
endMeasure(m: { name: string, mark: string }) {
performance.measure(m.name, m.mark);
},
recordPlacementTime(id: number, time: number) {
// Ignore placementTimes during loading
if (!fullLoadFinished) {
return;
}
if (placementTimes[id] == null) {
placementTimes[id] = [];
}

placementTimes[id].push(time);
},
frame(timestamp: number, isRenderFrame: boolean) {
// Ignore frametimes during loading
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we skip this for now and add while reviewing the rendering benchmarks more closely?

if (!fullLoadFinished) {
return;
}

const currTimestamp = timestamp;
if (lastFrameTime != null) {
const frameTime = currTimestamp - lastFrameTime;
Expand All @@ -78,6 +101,9 @@ export const PerformanceUtils = {
clearMetrics() {
lastFrameTime = null;
frameTimes = [];
placementTimes = {};
fullLoadFinished = false;

performance.clearMeasures('loadTime');
performance.clearMeasures('fullLoadTime');

Expand Down Expand Up @@ -149,6 +175,12 @@ export const PerformanceUtils = {
metrics.cpuFrameBudgetExceeded += Math.max(0, renderFrame.duration - CPU_FRAME_BUDGET);
}

let placementTime = 0;
for (const placement in placementTimes) {
placementTime += placementTimes[placement].reduce((prev, curr) => prev + curr, 0);
}
metrics.placementTime = placementTime;

return metrics;
},

Expand Down