File: FID.md

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (64 lines) | stat: -rw-r--r-- 4,261 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# First Input Delay

[First Input Delay](https://web.dev/fid) is a [Core Web Vital](https://web.dev/vitals) metric that reports the delay between when the browser receives the first input event and when the renderer begins processing it. This is a measure of how much main thread business affects user interaction.

This document details:
* [Where it is computed in the renderer](#Computation-in-Renderer)
* [How it is reported in trace events and web performance APIs](#Reporting-in-web-performance-APIs-and-trace-events)
* [How values from different frames are merged](#Merging-multiple-frames)
* [How it is reported to UKM/UMA](#Reporting-in-UKM-and-UMA)

## Computation in Renderer

Each time an event is dispatched, the event dispatcher calls
[`EventTiming::Create()`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/event_timing.cc;l=72;drc=054e08864177603f17edbc111db7ebc8586906bd;bpv=1;bpt=1)
which then calls the document's
[`InteractiveDetector::HandleForInputDelay()`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/loader/interactive_detector.cc;l=204;drc=054e08864177603f17edbc111db7ebc8586906bd),
which checks if this is the first event and stores the delay if so.

The `HandleForInputDelay` method calls
[`DocumentLoader::DidChangePerformanceTiming()`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/loader/document_loader.cc;drc=977dc02c431b4979e34c7792bc3d646f649dacb4;l=757)
which eventually causes
[`MetricsRenderFrameObserver::DidChangePerformanceTiming()`](https://source.chromium.org/chromium/chromium/src/+/main:components/page_load_metrics/renderer/metrics_render_frame_observer.cc;l=110?q=DidChangePerformanceTiming&ss=chromium%2Fchromium%2Fsrc&start=11)
to be called, ensuring the data is sent via mojo IPC to the browser, so that
[`PageLoadMetricsObserver`s](/chrome/browser/page_load_metrics/observers/README.md)
can merge frames and report the data to UKM.

## Reporting in web performance APIs and trace events

* First Input Delay is computed in the
  [Event Timing API](https://wicg.github.io/event-timing/) by subtracting the
  first event's `processingStart` from its `startTime`. An `EventTiming` object
  is created when the event dispatcher calls
  [`EventTiming::Create()`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/event_timing.cc;l=72;drc=054e08864177603f17edbc111db7ebc8586906bd;bpv=1;bpt=1), and the full event
  latency is computed in its destructor, which then calls
  [`WindowPerformance::RegisterEventTiming()`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/window_performance.cc;l=379;drc=054e08864177603f17edbc111db7ebc8586906bd)
  so the data can be reported in the performance timeline.
* Trace events are only emitted for very long First Input Delays (greater than
  575ms) in `InteractiveDetector::HandlerForInputDelay()`.

## Merging multiple frames

If multiple frames on a page have user input, the delay for the first of these
inputs is reported as the first input delay. The merge occurs in
[`PageLoadTimingMerger::MergeInteractiveTiming()`](https://source.chromium.org/chromium/chromium/src/+/main:components/page_load_metrics/browser/page_load_metrics_update_dispatcher.cc;l=354;drc=054e08864177603f17edbc111db7ebc8586906bd).

## Reporting in UKM and UMA

All Core Web Vitals UKM are reported via
[PageLoadMetricsObserver](/chrome/browser/page_load_metrics/observers/README.md).
This ensures consistent reporting of only main frames, excluding error pages, etc.

UKM for FID are:
* Most navigations: `PageLoad.InteractiveTiming.FirstInputDelay4`
* BFCache navigations:
  `HistoryNavigation.FirstInputDelayAfterBackForwardCacheRestore`
* Prerender2 activations:
  `PrerenderPageLoad.InteractiveTiming.FirstInputDelay4`

UMA for FID are:
* Most navigations: `PageLoad.InteractiveTiming.FirstInputDelay4`
* BFCache navigations:
  `PageLoad.InteractiveTiming.FirstInputDelay.AfterBackForwardCacheRestore`
* Prerender2 activations:
  `PageLoad.Clients.Prerender.InteractiveTiming.FirstInputDelay4.{SpeculationRule, Embedder_DirectURLInput, Embedder_DefaultSearchEngine}`