Measure performance

Measure input delay and engine layout and paint time with one summary per minute.

@docx-editor.dev/telemetry is available in version 2.29.0 and later.

The performance area measures input delay, engine layout, and paint time. It sends one summary per minute of use, never one event per key press.

Enable performance measurements

The following example sends performance events from about one editor in ten:

import { createTelemetry } from '@docx-editor.dev/telemetry';
import { otelExporter } from '@docx-editor.dev/telemetry/otel';

export const telemetry = createTelemetry({
  exporters: [otelExporter()],
  include: { performance: { sampleRate: 0.1 }, documentOpen: true, trackedChanges: true },
});

Sampling selects editors once, so each editor's summaries stay together. With a nonzero sampleRate, every editor measures and contributes metrics; sampling limits only events. Set sampleRate to 0 to stop performance measurement, metrics included.

Interpret timing summaries

A performance event covers up to one minute. The editor also flushes one when the page is hidden and when the editor is destroyed.

SummaryMeasuresExcludes
interactionKey or pointer press on a page to the next frame on screen, waiting for other work included.Modifier keys alone, presses while the page is hidden.
layoutMain-thread layout passes after edits or view changes such as zoom, background and superseded passes included.Layouts caused by document, font, or image loading. document.open reports the opening layout.
paintEach engine paint of the pages.None.
FieldMeaning
count, p50Ms, p95Ms, maxMsPer-summary timing statistics.
bandsTiming counts in bands ending at 16, 33, 50, 100, 200, 500, and 1000 ms, plus a band above 1000 ms.
windowMsFirst timing in the window to the summary. Includes idle time; use interaction.count for activity.
pagesBucketPage count bucket: 0, 1, 2-9, 10-99, 100-999, 1000+, or unknown before the first paint.

Events contain no keys, positions, or text. For active editing time, see Measure sessions, edits, and saves.

Detect slow interaction

The editor reports performance.slow-interaction, with a hint, after at least 20 timed presses when more than 5% take over 200 ms. The console exporter prints a warning; the Sentry exporter records a warning breadcrumb.

To find the cause, compare layout and paint for the same page bucket. Slow layout follows document size; slow paint follows the pages on screen.

Limits

  • Histogram bucket counts are exact. Sums are estimates from the bands.
  • A callbackExporter onMetric function receives one sample per timing, estimated at the middle of its band.
  • Sentry records performance events as breadcrumbs beside later errors.
  • The editor measures while any consumer requests it: telemetry.module with the area enabled and consent given, a module whose wantsDiagnostic returns true for 'performance', or an editor.on('diagnostic') handler.

See also