-
Notifications
You must be signed in to change notification settings - Fork 9.5k
core(network-request): switch to improved timing names #14721
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
Changes from all commits
381d671
ff0de30
8d8aa57
ab3e6bc
e1a9ca4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,42 +41,42 @@ class CriticalRequestChains extends Audit { | |
}; | ||
} | ||
|
||
/** @typedef {{depth: number, id: string, chainDuration: number, chainTransferSize: number, node: LH.Audit.Details.SimpleCriticalRequestNode[string]}} CrcNodeInfo */ | ||
/** @typedef {{depth: number, id: string, chainDuration: number, chainTransferSize: number, node: LH.Artifacts.CriticalRequestNode[string]}} CrcNodeInfo */ | ||
|
||
/** | ||
* @param {LH.Audit.Details.SimpleCriticalRequestNode} tree | ||
* @param {LH.Artifacts.CriticalRequestNode} tree | ||
* @param {function(CrcNodeInfo): void} cb | ||
*/ | ||
static _traverse(tree, cb) { | ||
/** | ||
* @param {LH.Audit.Details.SimpleCriticalRequestNode} node | ||
* @param {LH.Artifacts.CriticalRequestNode} node | ||
* @param {number} depth | ||
* @param {number=} startTime | ||
* @param {number=} networkRequestTime | ||
* @param {number=} transferSize | ||
*/ | ||
function walk(node, depth, startTime, transferSize = 0) { | ||
function walk(node, depth, networkRequestTime, transferSize = 0) { | ||
const children = Object.keys(node); | ||
if (children.length === 0) { | ||
return; | ||
} | ||
children.forEach(id => { | ||
const child = node[id]; | ||
if (!startTime) { | ||
startTime = child.request.startTime; | ||
if (!networkRequestTime) { | ||
networkRequestTime = child.request.networkRequestTime; | ||
} | ||
|
||
// Call the callback with the info for this child. | ||
cb({ | ||
depth, | ||
id, | ||
node: child, | ||
chainDuration: child.request.endTime - startTime, | ||
chainDuration: child.request.networkEndTime - networkRequestTime, | ||
chainTransferSize: transferSize + child.request.transferSize, | ||
}); | ||
|
||
// Carry on walking. | ||
if (child.children) { | ||
walk(child.children, depth + 1, startTime); | ||
walk(child.children, depth + 1, networkRequestTime); | ||
} | ||
}, ''); | ||
} | ||
|
@@ -86,7 +86,7 @@ class CriticalRequestChains extends Audit { | |
|
||
/** | ||
* Get stats about the longest initiator chain (as determined by time duration) | ||
* @param {LH.Audit.Details.SimpleCriticalRequestNode} tree | ||
* @param {LH.Artifacts.CriticalRequestNode} tree | ||
* @return {{duration: number, length: number, transferSize: number}} | ||
*/ | ||
static _getLongestChain(tree) { | ||
|
@@ -96,7 +96,7 @@ class CriticalRequestChains extends Audit { | |
transferSize: 0, | ||
}; | ||
CriticalRequestChains._traverse(tree, opts => { | ||
const duration = opts.chainDuration * 1000; | ||
const duration = opts.chainDuration; | ||
if (duration > longest.duration) { | ||
longest.duration = duration; | ||
longest.transferSize = opts.chainTransferSize; | ||
|
@@ -123,9 +123,9 @@ class CriticalRequestChains extends Audit { | |
const request = opts.node.request; | ||
const simpleRequest = { | ||
url: request.url, | ||
startTime: request.startTime / 1000, | ||
endTime: request.endTime / 1000, | ||
responseReceivedTime: request.responseReceivedTime / 1000, | ||
startTime: request.networkRequestTime / 1000, | ||
endTime: request.networkEndTime / 1000, | ||
responseReceivedTime: request.responseHeadersEndTime / 1000, | ||
transferSize: request.transferSize, | ||
}; | ||
|
||
|
@@ -199,7 +199,7 @@ class CriticalRequestChains extends Audit { | |
walk(initialNavChildren, 0); | ||
} | ||
|
||
const longestChain = CriticalRequestChains._getLongestChain(flattenedChains); | ||
const longestChain = CriticalRequestChains._getLongestChain(chains); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT this never made sense to run on |
||
|
||
return { | ||
score: Number(chainCount === 0), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,8 @@ class UsesRelPreconnectAudit extends Audit { | |
* @return {boolean} | ||
*/ | ||
static socketStartTimeIsBelowThreshold(record, mainResource) { | ||
return Math.max(0, record.startTime - mainResource.endTime) < PRECONNECT_SOCKET_MAX_IDLE_IN_MS; | ||
const timeSinceMainEnd = Math.max(0, record.networkRequestTime - mainResource.networkEndTime); | ||
return timeSinceMainEnd < PRECONNECT_SOCKET_MAX_IDLE_IN_MS; | ||
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the only other real code change, because it was kind of hard to read split over two lines. An intermediate variable seemed fine. |
||
} | ||
|
||
/** | ||
|
@@ -169,7 +170,7 @@ class UsesRelPreconnectAudit extends Audit { | |
// Sometimes requests are done simultaneous and the connection has not been made | ||
// chrome will try to connect for each network record, we get the first record | ||
const firstRecordOfOrigin = records.reduce((firstRecord, record) => { | ||
return (record.startTime < firstRecord.startTime) ? record : firstRecord; | ||
return (record.networkRequestTime < firstRecord.networkRequestTime) ? record : firstRecord; | ||
}); | ||
|
||
// Skip the origin if we don't have timing information | ||
|
@@ -186,8 +187,8 @@ class UsesRelPreconnectAudit extends Audit { | |
if (firstRecordOfOrigin.parsedURL.scheme === 'https') connectionTime = connectionTime * 2; | ||
|
||
const timeBetweenMainResourceAndDnsStart = | ||
firstRecordOfOrigin.startTime - | ||
mainResource.endTime + | ||
firstRecordOfOrigin.networkRequestTime - | ||
mainResource.networkEndTime + | ||
firstRecordOfOrigin.timing.dnsStart; | ||
|
||
const wastedMs = Math.min(connectionTime, timeBetweenMainResourceAndDnsStart); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file has the only real changes. This was actually always
LH.Artifacts.CriticalRequestNode
because the input was the (computed) artifact, withnode.request
being an actualNetworkRequest
, but previous to this PR that was actually structurally compatible with the simplifiedLH.Audit.Details.SimpleCriticalRequestNode
:lighthouse/types/lhr/audit-details.d.ts
Lines 32 to 42 in a2977ff
so the two types could be used interchangeably.
Since we don't want to change
LH.Audit.Details.SimpleCriticalRequestNode
, butnode.request
now hasnetworkRequestTime
, etc on it, this file needs to now actually differentiate between the two, and there needs to be a copy step from the new property names to the old property names on the audit details.Nothing actually changes in the output (see sample_v2.json for an example).