GoogleChrome / web-vitals

Essential metrics for a healthy site.
https://web.dev/vitals
Apache License 2.0
7.49k stars 410 forks source link

[LCP] Audit if eager stop of LCP is correct for cases where LCP is in-flight #389

Closed mmocny closed 11 months ago

mmocny commented 11 months ago

Today web-vitals.js will automatically stop the LCP algorithm in cases of measured discrete interaction. The list of interactions that we support is limited, and doesn't include all event types nor scroll.

But one thing I'm also not sure about:

Specifically, I'm wondering about cases where a large image is still loading, or still decoding.

Its possible that PerformanceObserver.tageRecords() will not return entries, but there are still entries "in flight".

(Note: There are similar issues with Event Timing and timings in-flight. Perhaps PerformanceObserver API should also have an async version of takeRecords() which will flush and report one last time...)

tunetheweb commented 11 months ago

Specifically, I'm wondering about cases where a large image is still loading, or still decoding.

I'm not sure there's a good answer here. Think of the following edge cases:

So I'm not sure the PO should fire in these cases, and that the web-vitals.js logic isn't the correct one to go with...

mmocny commented 11 months ago

I think you may have misunderstood my question-- I'm just saying that Chrome has already decided on answers to these questions and web-vitals shouldn't be making different decisions. Even if we want to change the answers, we should still try to synchronize.

I don't for sure yet if it differs, that's why I would like a (quick?) audit!


Here's what I think happens today:

I believe you are effectively guaranteed to get a next presentation time for that image, and an element timing / LCP entry for it, even if you scroll. That is because there is already a main-thread rendering update in the rendering pipeline and the presentation time will be the time that update is included in a screen update. I don't believe we necessarily track if the image was still within viewport at that point.

In other words, I suspect the LCP-halt-on-interaction heuristics stops new candidates from being queued up for measurement, rather than stopping LCP results from being added to timeline.

Not sure!

mmocny commented 11 months ago

Finished Audit. Looks like although image paints are measured until presentation time, even after input or scroll, those times end up discarded. The LCP calculator uses the main thread InputOrScroll time as the last point to capture recorded LCP times.