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(network-analyzer): fix num of roundtrips for h3 estimates #15102

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/computed/metrics/time-to-first-byte.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class TimeToFirstByte extends NavigationMetric {

// Estimate when the connection is not warm.
// TTFB = DNS + (SSL)? + TCP handshake + 1 RT for request + server response time
let roundTrips = 3;
let roundTrips = 2;
if (!mainResource.protocol.startsWith('h3')) roundTrips += 1; // TCP
if (mainResource.parsedURL.scheme === 'https') roundTrips += 1;
const estimatedTTFB = data.settings.throttling.rttMs * roundTrips + observedResponseTime;

Expand Down
5 changes: 3 additions & 2 deletions core/lib/dependency-graph/simulator/network-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ class NetworkAnalyzer {

// Assume everything before sendStart was just DNS + (SSL)? + TCP handshake
// 1 RT for DNS, 1 RT (maybe) for SSL, 1 RT for TCP
let roundTrips = 2;
let roundTrips = 1;
if (!record.protocol.startsWith('h3')) roundTrips += 1; // TCP
Copy link
Member

Choose a reason for hiding this comment

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

We should add this logic to TTFB as well.

WDYT about adding some kind of getRoundTripCount helper function to NetworkRequest so that we don't have to maintain this in 3 different places?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a bit more complicated than first glance to share this code, since the analyzer has its own concept of "is this connection reused?". I can try in a followup.

if (record.parsedURL.scheme === 'https') roundTrips += 1;
return timing.sendStart / roundTrips;
});
Expand Down Expand Up @@ -227,8 +228,8 @@ class NetworkAnalyzer {
// TTFB = DNS + (SSL)? + TCP handshake + 1 RT for request + server response time
if (!connectionReused) {
roundTrips += 1; // DNS
if (!record.protocol.startsWith('h3')) roundTrips += 1; // TCP
if (record.parsedURL.scheme === 'https') roundTrips += 1; // SSL
roundTrips += 1; // TCP handshake
}

// subtract out our estimated server response time
Expand Down