forked from GoogleChrome/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(metrics): add lantern EIL (GoogleChrome#5024)
- Loading branch information
1 parent
213fd6e
commit e393578
Showing
11 changed files
with
296 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
lighthouse-core/gather/computed/metrics/estimated-input-latency.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const MetricArtifact = require('./metric'); | ||
const LHError = require('../../../lib/errors'); | ||
const TracingProcessor = require('../../../lib/traces/tracing-processor'); | ||
|
||
const ROLLING_WINDOW_SIZE = 5000; | ||
|
||
/** | ||
* @fileoverview This audit determines the largest 90 percentile EQT value of all 5s windows between | ||
* FMP and the end of the trace. | ||
* @see https://docs.google.com/document/d/1b9slyaB9yho91YTOkAQfpCdULFkZM9LqsipcX3t7He8/preview | ||
*/ | ||
class EstimatedInputLatency extends MetricArtifact { | ||
get name() { | ||
return 'EstimatedInputLatency'; | ||
} | ||
|
||
/** | ||
* @param {Array<{start: number, end: number, duration: number}>} events | ||
* @return {number} | ||
*/ | ||
static calculateRollingWindowEIL(events) { | ||
const candidateStartEvts = events.filter(evt => evt.duration >= 10); | ||
|
||
let worst90thPercentileLatency = 16; | ||
for (const startEvt of candidateStartEvts) { | ||
const latencyPercentiles = TracingProcessor.getRiskToResponsiveness( | ||
events, | ||
startEvt.start, | ||
startEvt.start + ROLLING_WINDOW_SIZE, | ||
[0.9] | ||
); | ||
|
||
worst90thPercentileLatency = Math.max(latencyPercentiles[0].time, worst90thPercentileLatency); | ||
} | ||
|
||
return worst90thPercentileLatency; | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.MetricComputationData} data | ||
* @return {Promise<LH.Artifacts.Metric>} | ||
*/ | ||
computeObservedMetric(data) { | ||
const {firstMeaningfulPaint} = data.traceOfTab.timings; | ||
if (!firstMeaningfulPaint) { | ||
throw new LHError(LHError.errors.NO_FMP); | ||
} | ||
|
||
const events = TracingProcessor.getMainThreadTopLevelEvents( | ||
data.traceOfTab, | ||
firstMeaningfulPaint | ||
).filter(evt => evt.duration >= 1); | ||
|
||
return Promise.resolve({ | ||
timing: EstimatedInputLatency.calculateRollingWindowEIL(events), | ||
}); | ||
} | ||
} | ||
|
||
module.exports = EstimatedInputLatency; |
100 changes: 100 additions & 0 deletions
100
lighthouse-core/gather/computed/metrics/lantern-estimated-input-latency.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const LanternMetricArtifact = require('./lantern-metric'); | ||
const Node = require('../../../lib/dependency-graph/node'); | ||
const EstimatedInputLatency = require('./estimated-input-latency'); | ||
|
||
class LanternEstimatedInputLatency extends LanternMetricArtifact { | ||
get name() { | ||
return 'LanternEstimatedInputLatency'; | ||
} | ||
|
||
/** | ||
* @return {LH.Gatherer.Simulation.MetricCoefficients} | ||
*/ | ||
get COEFFICIENTS() { | ||
return { | ||
intercept: 0, | ||
optimistic: 0.4, | ||
pessimistic: 0.4, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {Node} dependencyGraph | ||
* @return {Node} | ||
*/ | ||
getOptimisticGraph(dependencyGraph) { | ||
return dependencyGraph; | ||
} | ||
|
||
/** | ||
* @param {Node} dependencyGraph | ||
* @return {Node} | ||
*/ | ||
getPessimisticGraph(dependencyGraph) { | ||
return dependencyGraph; | ||
} | ||
|
||
/** | ||
* @param {LH.Gatherer.Simulation.Result} simulation | ||
* @param {Object} extras | ||
* @return {LH.Gatherer.Simulation.Result} | ||
*/ | ||
getEstimateFromSimulation(simulation, extras) { | ||
// Intentionally use the opposite FMP estimate, a more pessimistic FMP means that more tasks | ||
// are excluded from the EIL computation, so a higher FMP means lower EIL for same work. | ||
const fmpTimeInMs = extras.optimistic | ||
? extras.fmpResult.pessimisticEstimate.timeInMs | ||
: extras.fmpResult.optimisticEstimate.timeInMs; | ||
|
||
const events = LanternEstimatedInputLatency.getEventsAfterFMP( | ||
simulation.nodeTimings, | ||
fmpTimeInMs | ||
); | ||
|
||
return { | ||
timeInMs: EstimatedInputLatency.calculateRollingWindowEIL(events), | ||
nodeTimings: simulation.nodeTimings, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.MetricComputationData} data | ||
* @param {Object} artifacts | ||
* @return {Promise<LH.Artifacts.LanternMetric>} | ||
*/ | ||
async compute_(data, artifacts) { | ||
const fmpResult = await artifacts.requestLanternFirstMeaningfulPaint(data, artifacts); | ||
return this.computeMetricWithGraphs(data, artifacts, {fmpResult}); | ||
} | ||
|
||
/** | ||
* @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings | ||
* @param {number} fmpTimeInMs | ||
*/ | ||
static getEventsAfterFMP(nodeTimings, fmpTimeInMs) { | ||
/** @type {Array<{start: number, end: number, duration: number}>} */ | ||
const events = []; | ||
for (const [node, timing] of nodeTimings.entries()) { | ||
if (node.type !== Node.TYPES.CPU) continue; | ||
if (!timing.endTime || !timing.startTime) continue; | ||
if (timing.endTime < fmpTimeInMs) continue; | ||
|
||
events.push({ | ||
start: timing.startTime, | ||
end: timing.endTime, | ||
duration: timing.endTime - timing.startTime, | ||
}); | ||
} | ||
|
||
return events; | ||
} | ||
} | ||
|
||
module.exports = LanternEstimatedInputLatency; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.