[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(server-response-time): use receiveHeadersStart instead of end #15155

Merged
merged 7 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
core(time-to-first-byte): use receiveHeadersStart
  • Loading branch information
connorjclark committed Jun 1, 2023
commit f953d1a3938be471a5de052a0e793bb6378e5e88
16 changes: 9 additions & 7 deletions core/computed/metrics/time-to-first-byte.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ class TimeToFirstByte extends NavigationMetric {
* @return {Promise<LH.Artifacts.Metric>}
*/
static async computeObservedMetric(data, context) {
const {processedNavigation} = data;
const timeOriginTs = processedNavigation.timestamps.timeOrigin;
const mainResource = await MainResource.request(data, context);
if (!mainResource.timing) {
throw new Error('missing timing for main resource');
}

// Technically TTFB is the start of the response headers not the end.
// That signal isn't available to us so we use header end time as a best guess.
const timestamp = mainResource.responseHeadersEndTime * 1000;
const timing = (timestamp - timeOriginTs) / 1000;

const {processedNavigation} = data;
const timeOriginTs = processedNavigation.timestamps.timeOrigin;
const timestampMs =
mainResource.timing.requestTime * 1000 + mainResource.timing.receiveHeadersStart;
const timestamp = timestampMs * 1000;
const timing = timestampMs - timeOriginTs / 1000;
return {timing, timestamp};
}
}
Expand Down
16 changes: 16 additions & 0 deletions core/lib/network-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class NetworkRequest {
}

this._updateResponseHeadersEndTimeIfNecessary();
this._backfillReceiveHeaderStartTiming();
this._updateTransferSizeForLightrider();
this._updateTimingsForLightrider();
}
Expand All @@ -293,6 +294,7 @@ class NetworkRequest {
this.localizedFailDescription = data.errorText;

this._updateResponseHeadersEndTimeIfNecessary();
this._backfillReceiveHeaderStartTiming();
this._updateTransferSizeForLightrider();
this._updateTimingsForLightrider();
}
Expand All @@ -315,6 +317,7 @@ class NetworkRequest {
this.networkEndTime = data.timestamp * 1000;

this._updateResponseHeadersEndTimeIfNecessary();
this._backfillReceiveHeaderStartTiming();
}

/**
Expand Down Expand Up @@ -449,6 +452,19 @@ class NetworkRequest {
}
}

/**
* TODO(compat): remove M116.
* `timing.receiveHeadersStart` was added recently, and will be in M116. Until then,
* set it to receiveHeadersEnd, which is close enough, to allow consumers of NetworkRequest
* to use the new field without accounting for this backcompat.
*/
_backfillReceiveHeaderStartTiming() {
// Do nothing if a value is already present!
if (!this.timing || this.timing.receiveHeadersStart !== undefined) return;

this.timing.receiveHeadersStart = this.timing.receiveHeadersEnd;
}

/**
* LR gets additional, accurate timing information from its underlying fetch infrastructure. This
* is passed in via X-Headers similar to 'X-TotalFetchedSize'.
Expand Down
2 changes: 1 addition & 1 deletion core/test/computed/metrics/time-to-first-byte-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function mockNetworkRecords() {
networkRequestTime: 300,
responseHeadersEndTime: 400,
networkEndTime: 500,
timing: {sendEnd: 0, receiveHeadersEnd: 100},
timing: {sendEnd: 0, receiveHeadersStart: 100},
transferSize: 16_000,
url: mainDocumentUrl,
frameId: 'ROOT_FRAME',
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"chrome-launcher": "^0.15.2",
"configstore": "^5.0.1",
"csp_evaluator": "1.1.1",
"devtools-protocol": "0.0.1130274",
"devtools-protocol": "0.0.1151065",
"enquirer": "^2.3.6",
"http-link-header": "^1.1.1",
"intl-messageformat": "^4.4.0",
Expand All @@ -215,8 +215,8 @@
"yargs-parser": "^21.0.0"
},
"resolutions": {
"puppeteer/**/devtools-protocol": "0.0.1130274",
"puppeteer-core/**/devtools-protocol": "0.0.1130274"
"puppeteer/**/devtools-protocol": "0.0.1151065",
"puppeteer-core/**/devtools-protocol": "0.0.1151065"
},
"repository": "GoogleChrome/lighthouse",
"keywords": [
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3002,10 +3002,10 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=

devtools-protocol@0.0.1120988, devtools-protocol@0.0.1130274:
version "0.0.1130274"
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.1130274.tgz#1cd0c472a84fc9a09becaaed35a247a6eab9310c"
integrity sha512-kIozBWajgsi1g0W8yzALI4ZdCp6KG1yWaq8NN1ehQM3zX6JRegLSzfexz7XT5eFjmq1RkpMYgeKmfi3GsHrCLw==
devtools-protocol@0.0.1120988, devtools-protocol@0.0.1151065:
version "0.0.1151065"
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.1151065.tgz#d7691671986617f3f3f806afe30c714254ac467a"
integrity sha512-2lYwxmian7ojCncbCennkq+xiymLza4MAaruCW078ORUzm+a8ZjYnYQxtk2h/3xXOM+9HGsYyWSR3UIhUfoSmQ==

diff-sequences@^28.0.2:
version "28.0.2"
Expand Down