Track largestContentfulPaint::candidate events in PerformanceTestBase and allow assertions on them

Created on 7 August 2023, over 1 year ago
Updated 7 October 2023, about 1 year ago

Problem/Motivation

Largest Contentful Paint isn't a single event in a page load, chrome first multiple 'largest contentful paint candidate' events - i.e. whatever the biggest most recent paint event was gets a new event, but because potentially the page could continue rendering at any moment, and add another, bigger, contentful paint, it doesn't report an actual LCP metric as such.

There are JavaScript libraries that do report a single LCP metric, but they have to be added to the page itself, this is good for production telemetry but it's less clean for lab testing which is what we're trying to do.

The current code in PerformanceTestBase hard codes a maximum of two LCP events (because that's the maximum in Umami at the moment), and a maximum of 30 seconds, and polls for them until it reaches either one, then gives up.

Probably we can do better than this, but it was the best I came up with. This was not helped by https://bugs.chromium.org/p/chromium/issues/detail?id=1463436 which took days (over a period of weeks) to track down and workaround too.

Steps to reproduce

Proposed resolution

One possible idea would be to allow the test itself to add an 'expected number of LCP events' when it's recording telemetry spans - so for some pages this might be one, for some two, for some three. Then for pages with one LCP event, we wouldn't need to wait for 2 or 30 seconds but would be done as soon as we get it.

We could even add an assertion on this - not on how long they take, but on how many there are. However this requires them being 100% reliable so we don't get false negatives/random test failures. I'd like to see the whole system running on commits before trying to adding the assertion so we can confirm it's reliable over time on gitlab's infra.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component
PHPUnit 

Last updated about 23 hours ago

Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @catch
  • 🇬🇧United Kingdom catch

    A possible idea here.

    Currently this hard-codes two LCP events and if there's only one LCP event it will poll for 30 seconds waiting for a second one until it gives up.

    Maybe we can look for other paint events, and if we're still getting some, keep polling, but if there's no more paint events (maybe other events too) give up. This might be efficient enough we can remove the short circuit when two LCP candidates are found too.

  • 🇬🇧United Kingdom catch

    #2 is covered by 📌 Random test failure in Drupal\Tests\demo_umami\FunctionalJavascript\PerformanceTest RTBC .

    However the original idea I had here might be worth doing - if we add count for the number of largestContentfulPaint::candidate events to PerformanceData, that would allow assertions on them. The main question is whether counting them is reliable across every single test run. Re-titling to focus on that.

Production build 0.71.5 2024