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(lantern): use fixed times for data URLs #9932

Merged
merged 2 commits into from
Nov 7, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lighthouse-core/lib/dependency-graph/network-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const BaseNode = require('./base-node.js');
const NetworkRequest = require('../network-request.js');
const URL = require('../url-shim.js');
Copy link
Member

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


class NetworkNode extends BaseNode {
/**
Expand Down Expand Up @@ -57,6 +58,23 @@ class NetworkNode extends BaseNode {
return !!this._record.fromDiskCache;
}

/**
* @return {boolean}
*/
get isNonNetworkProtocol() {
Copy link
Member

Choose a reason for hiding this comment

The 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);
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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}
*/
Expand Down
15 changes: 11 additions & 4 deletions lighthouse-core/lib/dependency-graph/simulator/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

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

Is this low compared to @paulirish's 10-15ms suggestion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

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

happy to use whatever we have clear evidence of

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 :)

Copy link
Member

Choose a reason for hiding this comment

The 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, {
Expand Down Expand Up @@ -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);
Expand Down
Loading