[go: nahoru, domu]

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

core: add time-to-first-byte and lcp-breakdown #14941

Merged
merged 40 commits into from
Apr 25, 2023
Merged

Conversation

adamraine
Copy link
Member
@adamraine adamraine commented Mar 31, 2023

This PR adds 3 new "metrics" to Lighthouse: TTFB, lcpLoadStart and lcpLoadEnd

lcpLoadStart and lcpLoadEnd are not the same as LCP load delay/load time because they are based at the timeOrigin rather than the end of the previous LCP phase.

The current simulated throttling variants of lcpLoadStart and lcpLoadEnd are just the observed metric value weighted by the throttled LCP value. As we discussed, this will be our starting point for analysis.

The current simulated throttling variant of TTFB is based on this calculation in the network analyzer:

// TTFB = DNS + (SSL)? + TCP handshake + 1 RT for request + server response time

Lantern correlations:

Screenshot 2023-04-18 at 1 59 49 PM

@adamraine adamraine requested a review from a team as a code owner March 31, 2023 19:00
@adamraine adamraine requested review from brendankenny and removed request for a team March 31, 2023 19:00
@brendankenny
Copy link
Member

Can you run on WPT from this branch so this doesn't have to land first?

@adamraine
Copy link
Member Author
adamraine commented Mar 31, 2023

We are getting the metrics from the Lighthouse within WPT so it would be nice to land this first (assuming WPT is pulling the latest release). It might be possible to do the same analysis from the trace artifacts returned by WPT though so it may not be 100% necessary to land this.

@adamraine

This comment was marked as outdated.

@adamraine

This comment was marked as outdated.


# Install dependencies
sudo apt-get update
sudo apt-get install -y xvfb nodejs google-chrome-stable google-cloud-sdk git zip
sudo npm install -g yarn

# Add a lighthouse user
sudo useradd -m -s $(which bash) -G sudo lighthouse
Copy link
Member Author
@adamraine adamraine Apr 11, 2023

Choose a reason for hiding this comment

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

I couldn't figure out why, but there is already a lighthouse user by this point in the script 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

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

Were you running on a fresh machine or re-using one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Pretty sure it was a fresh machine, I went through a few cycles of creating and removing machines named lantern-collect-instance

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's weird. Doesn't seem like it could work without this line.

The other gcp script does || echo "Lighthouse user already exists!", let's do that here too.

Copy link
Member

Choose a reason for hiding this comment

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

weirdly I got a lot of echoed "Lighthouse user already exists!" messages when running the regular gcp collect script as well. I also couldn't figure out why :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

You were both manually destroying the instance in the GCP dashboard each time? IIRC the script will silently-pass the instance-creation command if it already exists with those parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was manually destroying it

@adamraine
Copy link
Member Author

I've added tests for everything, and I think this PR is landable now. There might be some flakiness with the smokes but that should be pretty easy to patch.

The only thing left is to update the lantern database (this is why CI basics is failing). Once the rest of this PR is settled I will update the database and expectations. Or we could just exclude these new "metrics" from the lantern test for now.

@connorjclark connorjclark changed the title core: add ttfb, lcpLoad{Start,End} for wpt analysis core: add time-to-first-byte and lcp-breakdown Apr 19, 2023
Copy link
Member
@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

Looking good!

Mostly comments about tests, plus the one question about undefined vs ttfb for timing when LCP isn't an image

core/audits/predictive-perf.js Outdated Show resolved Hide resolved

const lcpRecord = await LCPImageRecord.request(data, context);
if (!lcpRecord) {
return {ttfb, loadStart: ttfb, loadEnd: ttfb};
Copy link
Member
@brendankenny brendankenny Apr 25, 2023

Choose a reason for hiding this comment

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

I think we might want to make loadStart/loadEnd undefined in these cases. The optimize-lcp article mentions making loadDelay/loadTime 0 (so setting these to ttfb), but that's technically only in the case where no resource outside the original HTML is needed for displaying the text. We don't track how fonts or dynamically added text were loaded, so we don't really know if there was another resource needed or not.

FWIW that would follow the approach taken in UKM, where loadStart/loadEnd are null/not recorded when the LCP is text/video (with implicit possible future TODOs for if/when video LCP happens and if text LCP timing is ever worth looking at)

Copy link
Member Author

Choose a reason for hiding this comment

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

I was somewhat worried that this would mess with the lantern metric comparisons. This might be reason enough to just leave it out of the lantern tests for this PR. I will keep the test data of course.

Copy link
Member Author
@adamraine adamraine Apr 25, 2023

Choose a reason for hiding this comment

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

Update, looks like lantern testing handles this just fine, I think I might still remove the lantern test stuff from this PR since we might want to regenerate the WPT again, and should probably use a real device.

},
"roughEstimateOfTTFB": {},
Copy link
Member

Choose a reason for hiding this comment

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

is the test failure that these need to be repopulated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we need to either update the lantern test database for that to happen, or remove these new "metrics" from lantern testing.

core/computed/metrics/time-to-first-byte.js Show resolved Hide resolved
core/test/audits/__snapshots__/metrics-test.js.snap Outdated Show resolved Hide resolved
core/computed/metrics/time-to-first-byte.js Show resolved Hide resolved
Copy link
Member
@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants