-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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(lantern): use fixed times for data URLs #9932
Changes from all commits
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
const BaseNode = require('./base-node.js'); | ||
const NetworkRequest = require('../network-request.js'); | ||
const URL = require('../url-shim.js'); | ||
|
||
class NetworkNode extends BaseNode { | ||
/** | ||
|
@@ -57,6 +58,23 @@ class NetworkNode extends BaseNode { | |
return !!this._record.fromDiskCache; | ||
} | ||
|
||
/** | ||
* @return {boolean} | ||
*/ | ||
get isNonNetworkProtocol() { | ||
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. What's up with all getters in this file? Kind of weird :) |
||
return URL.NON_NETWORK_PROTOCOLS.includes(this._record.protocol); | ||
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. Is it useful to reuse this here vs making a new list here? There are some non network protocols we wouldn't include here (presumably eg intent wouldn't end up as a node, but this list might expand in the future) 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. I'm not sure when this would actually need to diverge from our canonical set, so I'd prefer to reuse. It's true it will include things we don't actually need to test but I doubt the reverse will ever be true |
||
} | ||
|
||
|
||
/** | ||
* Returns whether this network record can be downloaded without a TCP connection. | ||
* During simulation we treat data coming in over a network connection separately from on-device data. | ||
* @return {boolean} | ||
patrickhulce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
get isConnectionless() { | ||
return this.fromDiskCache || this.isNonNetworkProtocol; | ||
} | ||
|
||
/** | ||
* @return {boolean} | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,8 +225,8 @@ class Simulator { | |
|
||
if (node.type !== BaseNode.TYPES.NETWORK) throw new Error('Unsupported'); | ||
|
||
// If a network request is cached, we can always start it, so skip the connection checks | ||
if (!node.fromDiskCache) { | ||
// If a network request is connectionless, we can always start it, so skip the connection checks | ||
if (!node.isConnectionless) { | ||
// Start a network request if we're not at max requests and a connection is available | ||
const numberOfActiveRequests = this._numberInProgress(node.type); | ||
if (numberOfActiveRequests >= this._maximumConcurrentRequests) return; | ||
|
@@ -295,10 +295,17 @@ class Simulator { | |
|
||
let timeElapsed = 0; | ||
if (networkNode.fromDiskCache) { | ||
// Rough access time for seeking to location on disk and reading sequentially = 8ms + 20ms/MB | ||
// Rough access time for seeking to location on disk and reading sequentially. | ||
// 8ms per seek + 20ms/MB | ||
// @see http://norvig.com/21-days.html#answers | ||
const sizeInMb = (record.resourceSize || 0) / 1024 / 1024; | ||
timeElapsed = 8 + 20 * sizeInMb - timingData.timeElapsed; | ||
} else if (networkNode.isNonNetworkProtocol) { | ||
// Estimates for the overhead of a data URL in Chromium and the decoding time for base64-encoded data. | ||
// 2ms per request + 10ms/MB | ||
// @see traces on https://dopiaza.org/tools/datauri/examples/index.php | ||
const sizeInMb = (record.resourceSize || 0) / 1024 / 1024; | ||
timeElapsed = 2 + 10 * sizeInMb - timingData.timeElapsed; | ||
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. Is this low compared to @paulirish's 10-15ms suggestion? 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. yeah but I couldn't find evidence to support that much overhead on some test pages and 10-15 seemed too high compared to our read from disk estimates, @paulirish do you have any docs we could link to to support 10-15ms? happy to use whatever we have clear evidence of 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.
I'd guess that @paulirish was ballparking, too, so let's call this good and we can revisit later if somehow these end up giving us bizarre lantern graphs or something (seems very unlikely :) 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. yah was just ballparking. I went looking in UMA yesterday but couldnt spot a relevant histogram. Seems fine for now. 👍 |
||
} else { | ||
const connection = this._connectionPool.acquireActiveConnectionFromRecord(record); | ||
const dnsResolutionTime = this._dns.getTimeUntilResolution(record, { | ||
|
@@ -342,7 +349,7 @@ class Simulator { | |
const timingData = this._getTimingData(node); | ||
const isFinished = timingData.estimatedTimeElapsed === timePeriodLength; | ||
|
||
if (node.type === BaseNode.TYPES.CPU || node.fromDiskCache) { | ||
if (node.type === BaseNode.TYPES.CPU || node.isConnectionless) { | ||
return isFinished | ||
? this._markNodeAsComplete(node, totalElapsedTime) | ||
: (timingData.timeElapsed += timePeriodLength); | ||
|
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.
We've got to rename this thing at some point