Skip to content

Commit 9c6ea6c

Browse files
CommanderStormCopilotkaigritunKai Gritundependabot[bot]
authored
feat: Add a demo how to implement performance metrics using our callbacks (#7077)
* document the performance metrics * expose PerformanceMetrics of the map * make the map and performance api work nicely with multiple map instances * write an performance example page * fix ts import * update index * reimplement the PerformanceMonitor without the small memory leak * rename the metrics * fix typo * simplify the code a bit * fix initalisation typing bug * add lastFrameTimeMs * add resetRuntimeMetrics * update docs * inital tests * fix naming * fix import * fix lints * add the reset function to the metrics example * bump bundle size * Apply suggestion from @CommanderStorm * refactor: make function and variable naming in `PerformanceUtils` more sensible (#7096) * rename the PerformanceUtils * make PerformanceUtils.remove adhere to how this is named across the codebase * document validateStyle better * change to different spelling * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @CommanderStorm --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * make the hash tests even more strict where the line between valid and invalid is (#7097) * fix: handle WebGL context loss when style is not loaded (#7094) * fix: handle WebGL context loss when style is not loaded Fix TypeError when WebGL context is lost before the map style is loaded. When a map is created without a style (or the style hasn't finished loading), this.style is null. The _contextLost handler was accessing this.style._layers and calling this.style.destroy() without checking if style exists first. This adds a null check around the style-dependent operations in the context lost handler. Fixes #7022 * refactor: invert if for readability, add changelog entry - Invert if (this.style) to early return for reduced indentation - Add changelog entry for the bug fix --------- Co-authored-by: Kai Gritun <kai@kaigritun.com> * chore(deps-dev): bump devtools-protocol from 0.0.1580600 to 0.0.1581282 (#7102) Bumps [devtools-protocol](https://github.com/ChromeDevTools/devtools-protocol) from 0.0.1580600 to 0.0.1581282. - [Commits](ChromeDevTools/devtools-protocol@v0.0.1580600...v0.0.1581282) --- updated-dependencies: - dependency-name: devtools-protocol dependency-version: 0.0.1581282 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump puppeteer from 24.37.1 to 24.37.2 (#7100) Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 24.37.1 to 24.37.2. - [Release notes](https://github.com/puppeteer/puppeteer/releases) - [Changelog](https://github.com/puppeteer/puppeteer/blob/main/CHANGELOG.md) - [Commits](puppeteer/puppeteer@puppeteer-v24.37.1...puppeteer-v24.37.2) --- updated-dependencies: - dependency-name: puppeteer dependency-version: 24.37.2 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump typedoc-plugin-markdown from 4.9.0 to 4.10.0 (#7101) Bumps [typedoc-plugin-markdown](https://github.com/typedoc2md/typedoc-plugin-markdown/tree/HEAD/packages/typedoc-plugin-markdown) from 4.9.0 to 4.10.0. - [Release notes](https://github.com/typedoc2md/typedoc-plugin-markdown/releases) - [Changelog](https://github.com/typedoc2md/typedoc-plugin-markdown/blob/main/packages/typedoc-plugin-markdown/CHANGELOG.md) - [Commits](https://github.com/typedoc2md/typedoc-plugin-markdown/commits/typedoc-plugin-markdown@4.10.0/packages/typedoc-plugin-markdown) --- updated-dependencies: - dependency-name: typedoc-plugin-markdown dependency-version: 4.10.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * reimplement using the observer pattern * Apply suggestion from @CommanderStorm * Apply suggestion from @CommanderStorm * Apply suggestion from @CommanderStorm * Apply suggestion from @CommanderStorm * remove the strip plugin * fix imports * fix naming * make the design more consistently named * integrate witht the documentation subsystem * Fix which items are exported for the docs * make the example more pretty * Apply suggestion from @CommanderStorm * fix linting errors * fix tests * add a testcase * simplify the LivecyclePerformanceObserver * make the naming clearer * add a marking observer * fix import * increase magic sourcemap number ???? * add more testcases * expose the marking observer * Update src/util/performance_observer/observer.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/examples/display-performance-metrics.html Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/examples/display-performance-metrics.html Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/examples/display-performance-metrics.html * add a changelog entry * implement in terms of the higher overhead event system * Apply suggestions from code review Co-authored-by: Frank Elsinga <frank@elsinga.de> * simplify the metrics example * Apply suggestion from @CommanderStorm * Apply suggestion from @CommanderStorm * simplify example * Apply suggestion from @CommanderStorm * Apply suggestions from code review Co-authored-by: Frank Elsinga <frank@elsinga.de> * Update typedoc.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * remove the now unnessary @rollup/plugin-strip --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Kai Gritun <kaigritun@gmail.com> Co-authored-by: Kai Gritun <kai@kaigritun.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent a12309c commit 9c6ea6c

13 files changed

Lines changed: 107 additions & 188 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## main
22
### ✨ Features and improvements
33
- _...Add new stuff here..._
4+
- Add example showing how to measure map performance using built-in events (`load`, `idle`, `render`) ([#7077](https://github.com/maplibre/maplibre-gl-js/pull/7077)) (by [@CommanderStorm](https://github.com/CommanderStorm))
45

56
### 🐞 Bug fixes
67
- Make `fitBounds` and `fitScreenCoordinates` respect the `zoomSnap` map option by snapping the zoom level down to keep bounds fully visible ([#7332](https://github.com/maplibre/maplibre-gl-js/issues/7332) (by [@CommanderStorm](https://github.com/CommanderStorm))

build/rollup_plugins.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import resolve from '@rollup/plugin-node-resolve';
44
import replace from '@rollup/plugin-replace';
55
import commonjs from '@rollup/plugin-commonjs';
66
import terser from '@rollup/plugin-terser';
7-
import strip from '@rollup/plugin-strip';
87
import {type Plugin} from 'rollup';
98
import json from '@rollup/plugin-json';
109
import {visualizer} from 'rollup-plugin-visualizer';
@@ -31,10 +30,6 @@ export const plugins = (production: boolean): Plugin[] => [
3130
'_token_stack:': ''
3231
}
3332
}),
34-
production && strip({
35-
sourceMap: true,
36-
functions: ['PerformanceUtils.*']
37-
}),
3833
production && terser({
3934
compress: {
4035
pure_getters: true,
181 KB
Loading

package-lock.json

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"@rollup/plugin-json": "^6.1.0",
4545
"@rollup/plugin-node-resolve": "^16.0.3",
4646
"@rollup/plugin-replace": "^6.0.3",
47-
"@rollup/plugin-strip": "^3.0.4",
4847
"@rollup/plugin-terser": "^1.0.0",
4948
"@rollup/plugin-typescript": "^12.1.4",
5049
"@stylistic/eslint-plugin": "^5.10.0",

src/source/geojson_worker_source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {getJSON} from '../util/ajax';
2-
import {RequestPerformance} from '../util/performance';
2+
import {RequestPerformance} from '../util/request_performance';
33
import {GeoJSONWrapper} from '@maplibre/vt-pbf';
44
import {EXTENT} from '../data/extent';
55
import {GeoJSONVT, type GeoJSONVTOptions} from '@maplibre/geojson-vt';

src/source/vector_tile_worker_source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {WorkerTile} from './worker_tile';
55
import {WorkerTileState, type ParsingState} from './worker_tile_state';
66
import {BoundedLRUCache} from '../tile/tile_cache';
77
import {extend} from '../util/util';
8-
import {RequestPerformance} from '../util/performance';
8+
import {RequestPerformance} from '../util/request_performance';
99
import {VectorTileOverzoomed, sliceVectorTileLayer, toVirtualVectorTile} from './vector_tile_overzoomed';
1010
import {MLTVectorTile} from './vector_tile_mlt';
1111
import type {

src/ui/map.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {Event, ErrorEvent, type Listener} from '../util/evented';
2222
import {type MapEventType, type MapLayerEventType, MapMouseEvent, type MapSourceDataEvent, type MapStyleDataEvent} from './events';
2323
import {TaskQueue} from '../util/task_queue';
2424
import {throttle} from '../util/throttle';
25-
import {PerformanceMarkers, PerformanceUtils} from '../util/performance';
2625
import {type Source} from '../source/source';
2726
import {type StyleLayer} from '../style/style_layer';
2827
import {Terrain} from '../render/terrain';
@@ -687,8 +686,6 @@ export class Map extends Camera {
687686
transformConstrain: TransformConstrainFunction | null;
688687

689688
constructor(options: MapOptions) {
690-
PerformanceUtils.mark(PerformanceMarkers.create);
691-
692689
const resolvedOptions = {...defaultOptions, ...options, canvasContextAttributes: {
693690
...defaultOptions.canvasContextAttributes,
694691
...options.canvasContextAttributes
@@ -3678,7 +3675,6 @@ export class Map extends Camera {
36783675

36793676
if (this.loaded() && !this._loaded) {
36803677
this._loaded = true;
3681-
PerformanceUtils.mark(PerformanceMarkers.load);
36823678
this.fire(new Event('load'));
36833679
}
36843680

@@ -3707,7 +3703,6 @@ export class Map extends Camera {
37073703

37083704
if (this._loaded && !this._fullyLoaded && !somethingDirty) {
37093705
this._fullyLoaded = true;
3710-
PerformanceUtils.mark(PerformanceMarkers.fullLoad);
37113706
}
37123707

37133708
return this;
@@ -3772,8 +3767,6 @@ export class Map extends Camera {
37723767
this._container.removeEventListener('scroll', this._onMapScroll, false);
37733768
this._container.classList.remove('maplibregl-map');
37743769

3775-
PerformanceUtils.remove();
3776-
37773770
this._removed = true;
37783771
this.fire(new Event('remove'));
37793772
}
@@ -3795,7 +3788,6 @@ export class Map extends Camera {
37953788
browser.frame(
37963789
this._frameRequest,
37973790
(paintStartTimeStamp) => {
3798-
PerformanceUtils.recordStartOfFrameAt(paintStartTimeStamp);
37993791
this._frameRequest = null;
38003792
try {
38013793
this._render(paintStartTimeStamp);

src/util/performance.ts

Lines changed: 0 additions & 146 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {describe, test, expect, beforeEach, afterEach, vi} from 'vitest';
2-
import {RequestPerformance} from './performance';
2+
import {RequestPerformance} from './request_performance';
33

44
describe('RequestPerformance', () => {
55
const url = 'http://example.com/test.json';

0 commit comments

Comments
 (0)