From 6b149968436ca9d8a1840d6ff754a8250c6498d3 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 18 Oct 2022 09:53:18 +0100 Subject: [PATCH] Merge pull request #9968 from overleaf/td-add-cm6-delete-metrics Add delete events to the CM6 performance metrics GitOrigin-RevId: 1adc65abda960037d40a7a7442d11a0980f6cd3a --- .../js/infrastructure/cm6-performance.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/services/web/frontend/js/infrastructure/cm6-performance.ts b/services/web/frontend/js/infrastructure/cm6-performance.ts index f112e288e8..fdf47492c0 100644 --- a/services/web/frontend/js/infrastructure/cm6-performance.ts +++ b/services/web/frontend/js/infrastructure/cm6-performance.ts @@ -6,16 +6,37 @@ const TIMER_MEASURE_NAME = 'CM6-Update' let latestDocLength = 0 +let performanceMeasureOptionsSupport = false + +// Check that performance.measure accepts an options object +try { + const testMeasureName = 'featureTest' + performance.measure(testMeasureName, { start: performance.now() }) + performance.clearMeasures(testMeasureName) + performanceMeasureOptionsSupport = true +} catch (e) {} + export function timedDispatch(dispatchFn: (tr: Transaction) => void) { return (tr: Transaction) => { + if (!performanceMeasureOptionsSupport) { + dispatchFn(tr) + return + } + performance.mark(TIMER_START_NAME) dispatchFn(tr) performance.mark(TIMER_END_NAME) - if (tr.isUserEvent('input')) { - performance.measure(TIMER_MEASURE_NAME, TIMER_START_NAME, TIMER_END_NAME) + const userEventType = tr.annotation(Transaction.userEvent) + + if (userEventType) { + performance.measure(TIMER_MEASURE_NAME, { + start: TIMER_START_NAME, + end: TIMER_END_NAME, + detail: { userEventType }, + }) } latestDocLength = tr.state.doc.length @@ -55,6 +76,9 @@ export function reportCM6Perf() { ) as PerformanceMeasure[] const inputDurations = cm6Entries + .filter(({ detail }) => + ['input', 'delete'].includes(detail.userEventType.split('.')[0]) + ) .map(({ duration }) => duration) .sort((a, b) => a - b)