Skip to content

Commit

Permalink
add back FMP
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Nov 6, 2017
1 parent 94bfb87 commit 8b0f2b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
38 changes: 36 additions & 2 deletions lighthouse-core/audits/predictive-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,36 @@ class PredictivePerf extends Audit {
});
}

/**
* @param {!Node} dependencyGraph
* @param {!TraceOfTabArtifact} traceOfTab
* @return {!Node}
*/
static getOptimisticFMPGraph(dependencyGraph, traceOfTab) {
const fmp = traceOfTab.timestamps.firstMeaningfulPaint;
return dependencyGraph.cloneWithRelationships(node => {
if (node.endTime > fmp || node.type === Node.TYPES.CPU) return false;
// Include non-script-initiated network requests with a render-blocking priority
return node.hasRenderBlockingPriority() && node.initiatorType !== 'script';
});
}

/**
* @param {!Node} dependencyGraph
* @param {!TraceOfTabArtifact} traceOfTab
* @return {!Node}
*/
static getPessimisticFMPGraph(dependencyGraph, traceOfTab) {
const fmp = traceOfTab.timestamps.firstMeaningfulPaint;
return dependencyGraph.cloneWithRelationships(node => {
if (node.endTime > fmp) return false;
// Include CPU tasks that performed a layout
if (node.type === Node.TYPES.CPU) return node.didPerformLayout();
// Include all network requests that had render-blocking priority (even script-initiated)
return node.hasRenderBlockingPriority();
});
}

/**
* @param {!Node} dependencyGraph
* @return {!Node}
Expand Down Expand Up @@ -149,6 +179,8 @@ class PredictivePerf extends Audit {
const graphs = {
optimisticFCP: PredictivePerf.getOptimisticFCPGraph(graph, traceOfTab),
pessimisticFCP: PredictivePerf.getPessimisticFCPGraph(graph, traceOfTab),
optimisticFMP: PredictivePerf.getOptimisticFMPGraph(graph, traceOfTab),
pessimisticFMP: PredictivePerf.getPessimisticFMPGraph(graph, traceOfTab),
optimisticTTCI: PredictivePerf.getOptimisticTTCIGraph(graph, traceOfTab),
pessimisticTTCI: PredictivePerf.getPessimisticTTCIGraph(graph, traceOfTab),
};
Expand All @@ -162,13 +194,15 @@ class PredictivePerf extends Audit {
switch (key) {
case 'optimisticFCP':
case 'pessimisticFCP':
case 'optimisticFMP':
case 'pessimisticFMP':
values[key] = estimate.timeInMs;
break;
case 'optimisticTTCI':
values[key] = Math.max(values.optimisticFCP, lastLongTaskEnd);
values[key] = Math.max(values.optimisticFMP, lastLongTaskEnd);
break;
case 'pessimisticTTCI':
values[key] = Math.max(values.pessimisticFCP, lastLongTaskEnd);
values[key] = Math.max(values.pessimisticFMP, lastLongTaskEnd);
break;
}

Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/test/audits/predictive-perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ describe('Performance: predictive performance audit', () => {

return PredictivePerf.audit(artifacts).then(output => {
assert.equal(output.score, 99);
assert.equal(Math.round(output.rawValue), 1513);
assert.equal(output.displayValue, '1,510\xa0ms');
assert.equal(Math.round(output.rawValue), 1333);
assert.equal(output.displayValue, '1,330\xa0ms');

const valueOf = name => Math.round(output.extendedInfo.value[name]);
assert.equal(valueOf('optimisticFCP'), 607);
assert.equal(valueOf('pessimisticFCP'), 607);
assert.equal(valueOf('optimisticFMP'), 754);
assert.equal(valueOf('pessimisticFMP'), 1191);
assert.equal(valueOf('optimisticTTCI'), 2438);
assert.equal(valueOf('pessimisticTTCI'), 2399);
});
Expand Down

0 comments on commit 8b0f2b9

Please sign in to comment.