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

Implement the "Underutilized network time" metric #4901

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions src/source/source_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {SourceSpecification} from '@maplibre/maplibre-gl-style-spec';
import type {MapSourceDataEvent} from '../ui/events';
import type {Terrain} from '../render/terrain';
import type {CanvasSourceSpecification} from './canvas_source';
import {PerformanceMarkers, PerformanceUtils} from '../util/performance';

type TileResult = {
tile: Tile;
Expand Down Expand Up @@ -173,8 +174,11 @@ export class SourceCache extends Evented {
}

async _loadTile(tile: Tile, id: string, state: TileState): Promise<void> {
PerformanceUtils.mark(PerformanceMarkers.lastTileRequested);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this add some tileId data to the performance?


try {
await this._source.loadTile(tile);
PerformanceUtils.mark(PerformanceMarkers.tileReceived);
this._tileLoaded(tile, id, state);
} catch (err) {
tile.state = 'errored';
Expand Down
2 changes: 2 additions & 0 deletions src/source/worker_tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {PromoteIdSpecification} from '@maplibre/maplibre-gl-style-spec';
import type {VectorTile} from '@mapbox/vector-tile';
import {MessageType, type GetGlyphsResponse, type GetImagesResponse} from '../util/actor_messages';
import type {SubdivisionGranularitySetting} from '../render/subdivision_granularity_settings';
import {PerformanceMarkers, PerformanceUtils} from '../util/performance';

export class WorkerTile {
tileID: OverscaledTileID;
Expand Down Expand Up @@ -160,6 +161,7 @@ export class WorkerTile {
getPatternsPromise = actor.sendAsync({type: MessageType.getImages, data: {icons: patterns, source: this.source, tileID: this.tileID, type: 'patterns'}}, abortController);
}

PerformanceUtils.mark(PerformanceMarkers.glyphsRequested);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this happens in the worker thread, not sure you reach it in the main thread...?

const [glyphMap, iconMap, patternMap] = await Promise.all([getGlyphsPromise, getIconsPromise, getPatternsPromise]);
const glyphAtlas = new GlyphAtlas(glyphMap);
const imageAtlas = new ImageAtlas(iconMap, patternMap);
Expand Down
2 changes: 2 additions & 0 deletions src/style/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
} from '../util/actor_messages';
import {Projection} from '../geo/projection/projection';
import {createProjectionFromName} from '../geo/projection/projection_factory';
import {PerformanceMarkers, PerformanceUtils} from '../util/performance';

const empty = emptyStyle() as StyleSpecification;
/**
Expand Down Expand Up @@ -317,6 +318,7 @@ export class Style extends Evented {
this._frameRequest = null;
options.validate = options.validate !== false;
this._load(json, options, previousStyle);
PerformanceUtils.mark(PerformanceMarkers.styleLoaded);
}).catch(() => {}); // ignore abort
}

Expand Down
5 changes: 5 additions & 0 deletions src/ui/handler_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {extend} from '../util/util';
import {browser} from '../util/browser';
import Point from '@mapbox/point-geometry';
import {MapControlsDeltas} from '../geo/projection/camera_helper';
import {PerformanceMarkers, PerformanceUtils} from '../util/performance';

const isMoving = (p: EventsInProgress) => p.zoom || p.drag || p.roll || p.pitch || p.rotate;

Expand Down Expand Up @@ -359,6 +360,10 @@ export class HandlerManager {
}

handleEvent = (e: Event, eventName?: keyof Handler) => {
if (e.type === 'moveend' || e.type === 'zoomend' || e.type === 'rotateend') {
Copy link
Collaborator

@HarelM HarelM Oct 26, 2024

Choose a reason for hiding this comment

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

rollend? pitchend? bearingend?

// When viewport change ends and we know what new tiles we need
PerformanceUtils.mark(PerformanceMarkers.viewportChanged);
}

if (e.type === 'blur') {
this.stop(true);
Expand Down
28 changes: 27 additions & 1 deletion src/util/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
totalFrames: number;
};

export type NetworkUtilizationMetrics = {
viewportToTilesDelay: number; // Time between viewport change and tile requests
styleToTilesDelay: number; // Time between style load and tile requests
tileToGlyphsDelay: number; // Time between tile load and glyph requests
};

export enum PerformanceMarkers {
create = 'create',
load = 'load',
fullLoad = 'fullLoad'
fullLoad = 'fullLoad',

styleLoaded = 'styleLoaded',
lastTileRequested = 'lastTileRequested',
tileReceived = 'tileReceived',
glyphsRequested = 'glyphsRequested',
viewportChanged = 'viewportChanged'
}

let lastFrameTime = null;
Expand All @@ -25,7 +37,7 @@

export const PerformanceUtils = {
mark(marker: PerformanceMarkers) {
performance.mark(marker);

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › filters by `layers` option

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › filters by `layers` option

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › filters by `layers` option

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › filters by `layers` option

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › filters by `layers` option as a Set

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › filters by `layers` option as a Set

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › filters by `layers` option as a Set

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › filters by `layers` option as a Set

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › checks type of `layers` option

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)

Check failure on line 40 in src/util/performance.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

Style#queryRenderedFeatures › checks type of `layers` option

TypeError: performance.mark is not a function at Object.mark (src/util/performance.ts:40:21) at SourceCache._loadTile (src/source/source_cache.ts:177:26) at SourceCache._addTile (src/source/source_cache.ts:870:18) at SourceCache._updateRetainedTiles (src/source/source_cache.ts:714:31) at SourceCache.update (src/source/source_cache.ts:670:29) at SourceCache._dataHandler (src/source/source_cache.ts:937:22) at SourceCache.<anonymous> (src/source/source_cache.ts:96:57) at SourceCache.fire (src/util/evented.ts:128:26) at GeoJSONSource.fire (src/util/evented.ts:143:24) at GeoJSONSource._updateWorkerData (src/source/geojson_source.ts:363:18) at GeoJSONSource.load (src/source/geojson_source.ts:200:9)
},
frame(timestamp: number) {
const currTimestamp = timestamp;
Expand Down Expand Up @@ -71,6 +83,20 @@
percentDroppedFrames,
totalFrames
};
},

getNetworkUtilizationMetrics(): NetworkUtilizationMetrics {
const styleLoadTime = performance.getEntriesByName(PerformanceMarkers.styleLoaded)[0]?.startTime || 0;
const lastTileRequestTime = performance.getEntriesByName(PerformanceMarkers.lastTileRequested)[0]?.startTime || 0;
const tileReceiveTime = performance.getEntriesByName(PerformanceMarkers.tileReceived)[0]?.startTime || 0;
const glyphsRequestTime = performance.getEntriesByName(PerformanceMarkers.glyphsRequested)[0]?.startTime || 0;
const viewportChangeTime = performance.getEntriesByName(PerformanceMarkers.viewportChanged)[0]?.startTime || 0;

return {
styleToTilesDelay: lastTileRequestTime - styleLoadTime,
tileToGlyphsDelay: glyphsRequestTime - tileReceiveTime,
viewportToTilesDelay: lastTileRequestTime - viewportChangeTime
};
}
};

Expand Down
Loading