Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cap INP breakdowns to INP duration #528

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/attribution/onINP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,16 @@ const getIntersectingLoAFs = (

const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
const firstEntry = metric.entries[0];
const inpTime = firstEntry.startTime + metric.value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: just call it endTime or something

const group = entryToEntriesGroupMap.get(firstEntry)!;

const processingStart = firstEntry.processingStart;
const processingEnd = group.processingEnd;
// processingEnd can extend beyond duration for modals where we artificially
// mark event timing duration as that paint.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "as that paint" comment is confusing (there is no actual paint)

Perhaps just "where duration ends at the time modal dialog started (and provided visual feedback)"

// See: https://github.com/GoogleChrome/web-vitals/issues/492
// So cap to the INP value.
const processingEnd =
group.processingEnd >= inpTime ? inpTime : group.processingEnd;

// Sort the entries in processing time order.
const processedEventEntries = group.entries.sort((a, b) => {
Expand Down Expand Up @@ -274,6 +280,10 @@ const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
);

const nextPaintTime = Math.max.apply(Math, nextPaintTimeCandidates);
// If processingEnd has been capped to inpTime then presentationDelay is 0
// Else use the nextPaintTime
const presentationDelay =
processingEnd == inpTime ? 0 : Math.max(nextPaintTime - processingEnd, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a fine temporary solution, but, consider just creating a variable such as "used_fallback_time", set up top when endTime < processingEnd, and re-use that everywhere.

(The goal is to expose a clue to event timing for this value, eventually.)

BTW the case where endTime is rounded to within 8ms of processingEnd is almost always another "used_fallback_time" example (i.e. when we actually dont have a paint)


const attribution: INPAttribution = {
interactionTarget: getSelector(interactionTargetElement),
Expand All @@ -285,7 +295,7 @@ const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
longAnimationFrameEntries: longAnimationFrameEntries,
inputDelay: processingStart - firstEntry.startTime,
processingDuration: processingEnd - processingStart,
presentationDelay: Math.max(nextPaintTime - processingEnd, 0),
presentationDelay: presentationDelay,
loadState: getLoadState(firstEntry.startTime),
};

Expand Down