Просмотр исходного кода

Merge pull request #9968 from overleaf/td-add-cm6-delete-metrics

Add delete events to the CM6 performance metrics

GitOrigin-RevId: 1adc65abda960037d40a7a7442d11a0980f6cd3a
Alf Eaton 3 лет назад
Родитель
Сommit
6b14996843
1 измененных файлов с 26 добавлено и 2 удалено
  1. 26 2
      services/web/frontend/js/infrastructure/cm6-performance.ts

+ 26 - 2
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)