From 84b47b935a1c6fb99c986ed9df6d6866177016b3 Mon Sep 17 00:00:00 2001 From: Ryan Hamley Date: Fri, 22 Jan 2021 14:41:24 -0800 Subject: [PATCH] Dedupe calls to performance.measure --- src/source/vector_tile_worker_source.js | 3 ++- src/util/performance.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/source/vector_tile_worker_source.js b/src/source/vector_tile_worker_source.js index e642f598931..72c242875c6 100644 --- a/src/source/vector_tile_worker_source.js +++ b/src/source/vector_tile_worker_source.js @@ -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 diff --git a/src/util/performance.js b/src/util/performance.js index d03a8e94170..e5548f4939d 100644 --- a/src/util/performance.js +++ b/src/util/performance.js @@ -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);