Skip to content

Commit

Permalink
core(byte-efficiency): replace pessimistic graph with optimistic (#15651
Browse files Browse the repository at this point in the history
)
  • Loading branch information
adrianaixba committed Dec 8, 2023
1 parent 9ce7626 commit c4d02c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
10 changes: 6 additions & 4 deletions core/audits/byte-efficiency/byte-efficiency-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ class ByteEfficiencyAudit extends Audit {
if (metricComputationInput.gatherContext.gatherMode === 'navigation') {
const graph = await PageDependencyGraph.request(metricComputationInput, context);
const {
pessimisticGraph: pessimisticFCPGraph,
optimisticGraph: optimisticFCPGraph,
} = await LanternFirstContentfulPaint.request(metricComputationInput, context);
const {
pessimisticGraph: pessimisticLCPGraph,
optimisticGraph: optimisticLCPGraph,
} = await LanternLargestContentfulPaint.request(metricComputationInput, context);

wastedMs = this.computeWasteWithTTIGraph(results, graph, simulator, {
Expand All @@ -218,17 +218,19 @@ class ByteEfficiencyAudit extends Audit {

const {savings: fcpSavings} = this.computeWasteWithGraph(
results,
pessimisticFCPGraph,
optimisticFCPGraph,
simulator,
{providedWastedBytesByUrl: result.wastedBytesByUrl, label: 'fcp'}
);
// Note: LCP's optimistic graph sometimes unexpectedly yields higher savings than the pessimistic graph.
const {savings: lcpGraphSavings} = this.computeWasteWithGraph(
results,
pessimisticLCPGraph,
optimisticLCPGraph,
simulator,
{providedWastedBytesByUrl: result.wastedBytesByUrl, label: 'lcp'}
);


// The LCP graph can underestimate the LCP savings if there is potential savings on the LCP record itself.
let lcpRecordSavings = 0;
const lcpRecord = await LCPImageRecord.request(metricComputationInput, context);
Expand Down
24 changes: 12 additions & 12 deletions core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4552,7 +4552,7 @@
"warnings": [],
"metricSavings": {
"FCP": 0,
"LCP": 300
"LCP": 610
},
"details": {
"type": "opportunity",
Expand Down Expand Up @@ -4590,7 +4590,7 @@
"type": "debugdata",
"metricSavings": {
"FCP": 0,
"LCP": 300
"LCP": 610
}
}
},
Expand Down Expand Up @@ -4639,7 +4639,7 @@
"displayValue": "Potential savings of 63 KiB",
"metricSavings": {
"FCP": 0,
"LCP": 450
"LCP": 300
},
"details": {
"type": "opportunity",
Expand Down Expand Up @@ -4693,7 +4693,7 @@
"type": "debugdata",
"metricSavings": {
"FCP": 0,
"LCP": 450
"LCP": 300
}
}
},
Expand Down Expand Up @@ -4862,7 +4862,7 @@
"displayValue": "Potential savings of 143 KiB",
"metricSavings": {
"FCP": 150,
"LCP": 750
"LCP": 1060
},
"details": {
"type": "opportunity",
Expand Down Expand Up @@ -4904,7 +4904,7 @@
"type": "debugdata",
"metricSavings": {
"FCP": 150,
"LCP": 750
"LCP": 1060
}
}
},
Expand Down Expand Up @@ -4946,14 +4946,14 @@
"id": "efficient-animated-content",
"title": "Use video formats for animated content",
"description": "Large GIFs are inefficient for delivering animated content. Consider using MPEG4/WebM videos for animations and PNG/WebP for static images instead of GIF to save network bytes. [Learn more about efficient video formats](https://developer.chrome.com/docs/lighthouse/performance/efficient-animated-content/)",
"score": 0,
"score": 0.5,
"scoreDisplayMode": "metricSavings",
"numericValue": 3450,
"numericUnit": "millisecond",
"displayValue": "Potential savings of 666 KiB",
"metricSavings": {
"FCP": 0,
"LCP": 3300
"LCP": 0
},
"details": {
"type": "opportunity",
Expand Down Expand Up @@ -4990,7 +4990,7 @@
"type": "debugdata",
"metricSavings": {
"FCP": 0,
"LCP": 3300
"LCP": 0
}
}
},
Expand Down Expand Up @@ -5032,14 +5032,14 @@
"id": "legacy-javascript",
"title": "Avoid serving legacy JavaScript to modern browsers",
"description": "Polyfills and transforms enable legacy browsers to use new JavaScript features. However, many aren't necessary for modern browsers. For your bundled JavaScript, adopt a modern script deployment strategy using module/nomodule feature detection to reduce the amount of code shipped to modern browsers, while retaining support for legacy browsers. [Learn how to use modern JavaScript](https://web.dev/articles/publish-modern-javascript)",
"score": 0.5,
"score": 0,
"scoreDisplayMode": "metricSavings",
"numericValue": 450,
"numericUnit": "millisecond",
"displayValue": "Potential savings of 26 KiB",
"metricSavings": {
"FCP": 0,
"LCP": 0
"LCP": 150
},
"details": {
"type": "opportunity",
Expand Down Expand Up @@ -5108,7 +5108,7 @@
"type": "debugdata",
"metricSavings": {
"FCP": 0,
"LCP": 0
"LCP": 150
}
}
},
Expand Down

0 comments on commit c4d02c6

Please sign in to comment.