Skip to content

Commit

Permalink
Dedupe calls to performance.measure
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Jan 22, 2021
1 parent 10f45ed commit 84b47b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/source/vector_tile_worker_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ class VectorTileWorkerSource implements WorkerSource {
if (response.cacheControl) cacheControl.cacheControl = response.cacheControl;

const resourceTiming = {};
if (perf) {
// because of two-phase tile loading, it's necessary to dedupe perf marking to avoid errors
if (perf && !perf._marksWereCleared()) {
const resourceTimingData = perf.finish();
// it's necessary to eval the result of getEntriesByName() here via parse/stringify
// late evaluation in the main thread causes TypeError: illegal invocation
Expand Down
4 changes: 4 additions & 0 deletions src/util/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ export class RequestPerformance {

performance.mark(this._marks.start);
}

_marksWereCleared() {
return performance.getEntriesByName(this._marks.start).length === 0;
}

finish() {
performance.mark(this._marks.end);
Expand Down

0 comments on commit 84b47b9

Please sign in to comment.