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

Add delete events to the CM6 performance metrics

GitOrigin-RevId: 1adc65abda960037d40a7a7442d11a0980f6cd3a
This commit is contained in:
Alf Eaton 2022-10-18 09:53:18 +01:00 committed by Copybot
parent 27686264f4
commit 6b14996843

View file

@ -6,16 +6,37 @@ const TIMER_MEASURE_NAME = 'CM6-Update'
let latestDocLength = 0 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) { export function timedDispatch(dispatchFn: (tr: Transaction) => void) {
return (tr: Transaction) => { return (tr: Transaction) => {
if (!performanceMeasureOptionsSupport) {
dispatchFn(tr)
return
}
performance.mark(TIMER_START_NAME) performance.mark(TIMER_START_NAME)
dispatchFn(tr) dispatchFn(tr)
performance.mark(TIMER_END_NAME) performance.mark(TIMER_END_NAME)
if (tr.isUserEvent('input')) { const userEventType = tr.annotation(Transaction.userEvent)
performance.measure(TIMER_MEASURE_NAME, TIMER_START_NAME, TIMER_END_NAME)
if (userEventType) {
performance.measure(TIMER_MEASURE_NAME, {
start: TIMER_START_NAME,
end: TIMER_END_NAME,
detail: { userEventType },
})
} }
latestDocLength = tr.state.doc.length latestDocLength = tr.state.doc.length
@ -55,6 +76,9 @@ export function reportCM6Perf() {
) as PerformanceMeasure[] ) as PerformanceMeasure[]
const inputDurations = cm6Entries const inputDurations = cm6Entries
.filter(({ detail }) =>
['input', 'delete'].includes(detail.userEventType.split('.')[0])
)
.map(({ duration }) => duration) .map(({ duration }) => duration)
.sort((a, b) => a - b) .sort((a, b) => a - b)