-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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(metrics): add lantern EIL #5024
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f1801b2
core(metrics): add lantern EIL
patrickhulce 9a7fdaf
add to metrics/predictive-perf output
patrickhulce d8041b2
Merge branch 'master' into lantern_eil
patrickhulce ed16f44
update sample json
patrickhulce bdf7cfa
nodeTimings
patrickhulce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.nodeTiming, | ||
fmpTimeInMs | ||
); | ||
|
||
return { | ||
timeInMs: EstimatedInputLatency.calculateRollingWindowEIL(events), | ||
nodeTiming: simulation.nodeTiming, | ||
}; | ||
} | ||
|
||
/** | ||
* @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 {Map<Node, LH.Gatherer.Simulation.NodeTiming>} nodeTiming | ||
* @param {number} fmpTimeInMs | ||
*/ | ||
static getEventsAfterFMP(nodeTiming, fmpTimeInMs) { | ||
/** @type {Array<{start: number, end: number, duration: number}>} */ | ||
const events = []; | ||
for (const [node, timing] of nodeTiming.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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think the conflict is just
v2/
->html/
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.
👍 done