Skip to content

Missing LoAF attributions for INP due to violating internal invariants #511

Closed
@brendankenny

Description

@brendankenny

#487 introduced a bug that we didn't notice that reduces (often significantly) the number of INPs that get LoAF attribution.

The extra loop added to keep LoAFs that happened after all known events

for (let i = 0; i < MAX_PREVIOUS_FRAMES; i++) {
// Look at pending LoAF in reverse order so the most recent are first.
const loaf = pendingLoAFs[pendingLoAFs.length - 1 - i];
// If we reach LoAFs that overlap with event processing,
// we can assume all previous ones have already been handled.
if (!loaf || loaf.startTime < latestProcessingEnd) break;
loafsToKeep.add(loaf);
}

works as expected and is only additive to the LoAFs kept for potential attribution before #487. The problem is that it adds to the loafsToKeep set as a second batch of LoAFs, after the first loop through the LoAFs.

When the new array of LoAFs is created from this set (pendingLoAFs = Array.from(loafsToKeep)), the pendingLoAFs array is now ordered by how values were inserted into loafsToKeep. This is bad because pendingLoAFs is assumed to be in startTime order by getIntersectingLoAFs, which will quit looking for intersecting LoAFs early if it thinks it's reached the end of possible intersections:

// If the LoAF starts after the given end time, ignore it and all
// subsequent pending LoAFs (because they're in time order).
if (loaf.startTime > end) break;

All the correct LoAFs are in pendingLoAFs, but getIntersectingLoAFs gives up before seeing them. I believe this tends to get worse for busier or longer-lived pages because LoAFs that happened after any known interaction events get put last in this array initially, then they get paired with some event group as events come in so get put into the first batch of LoAFs in the loafsToKeep Set. But they're now (potentially) out of order in that batch, spreading the disorder throughout the pendingLoAFs array.

Fix: don't do that :) e.g. sort or filter from the existing sorted array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions