From 2ada2681b48ad194bf0c8006ebb23d58bad4f473 Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Wed, 19 Apr 2023 16:03:04 -0700 Subject: [PATCH 1/6] core: add metric savings to audit result --- core/audits/audit.js | 1 + core/audits/third-party-summary.js | 3 +++ types/audit.d.ts | 3 +++ types/lhr/audit-result.d.ts | 10 ++++++++++ 4 files changed, 17 insertions(+) diff --git a/core/audits/audit.js b/core/audits/audit.js index f44f617692af..4d3ca0d77c5e 100644 --- a/core/audits/audit.js +++ b/core/audits/audit.js @@ -410,6 +410,7 @@ class Audit { warnings: product.warnings, details: product.details, + metricSavings: product.metricSavings, }; } } diff --git a/core/audits/third-party-summary.js b/core/audits/third-party-summary.js index a2e67df5e1e3..8b7756cfea70 100644 --- a/core/audits/third-party-summary.js +++ b/core/audits/third-party-summary.js @@ -252,6 +252,9 @@ class ThirdPartySummary extends Audit { timeInMs: overallSummary.wastedMs, }), details, + metricSavings: { + TBT: overallSummary.wastedMs, + }, }; } } diff --git a/types/audit.d.ts b/types/audit.d.ts index 25ecd139c345..a7c61930b432 100644 --- a/types/audit.d.ts +++ b/types/audit.d.ts @@ -18,6 +18,7 @@ declare module Audit { export type Result = AuditResult.Result; export type ScoreDisplayMode = AuditResult.ScoreDisplayMode; export type ScoreDisplayModes = AuditResult.ScoreDisplayModes; + export type MetricSavings = AuditResult.MetricSavings; type Context = Util.Immutable<{ /** audit options */ @@ -81,6 +82,8 @@ declare module Audit { details?: AuditDetails; /** If an audit encounters unusual execution circumstances, strings can be put in this optional array to add top-level warnings to the LHR. */ runWarnings?: Array; + /** Estimates of how much this audit affects various performance metrics. Values will be in the init of their respective metrics. */ + metricSavings?: MetricSavings; } /** The Audit.Product type for audits that do not return a `numericValue`. */ diff --git a/types/lhr/audit-result.d.ts b/types/lhr/audit-result.d.ts index b8285eca4bd9..2b6c9d0c96f4 100644 --- a/types/lhr/audit-result.d.ts +++ b/types/lhr/audit-result.d.ts @@ -24,6 +24,14 @@ interface ScoreDisplayModes { type ScoreDisplayMode = ScoreDisplayModes[keyof ScoreDisplayModes]; +interface MetricSavings { + LCP?: number; + FCP?: number; + CLS?: number; + TBT?: number; + INP?: number; +} + /** Audit result returned in Lighthouse report. All audits offer a description and score of 0-1. */ export interface Result { displayValue?: string; @@ -50,6 +58,8 @@ export interface Result { id: string; /** A more detailed description that describes why the audit is important and links to Lighthouse documentation on the audit; markdown links supported. */ description: string; + /** Estimates of how much this audit affects various performance metrics. Values will be in the init of their respective metrics. */ + metricSavings?: MetricSavings; /** A numeric value that has a meaning specific to the audit, e.g. the number of nodes in the DOM or the timestamp of a specific load event. More information can be found in the audit details, if present. */ numericValue?: number; /** The unit of `numericValue`, used when the consumer wishes to convert numericValue to a display string. */ From 834e3e9377e8b6c08f27cdfe4d3f9f2a75a88ba3 Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Wed, 19 Apr 2023 16:05:18 -0700 Subject: [PATCH 2/6] comments --- types/audit.d.ts | 2 +- types/lhr/audit-result.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/audit.d.ts b/types/audit.d.ts index a7c61930b432..0fa3cbfdabf9 100644 --- a/types/audit.d.ts +++ b/types/audit.d.ts @@ -82,7 +82,7 @@ declare module Audit { details?: AuditDetails; /** If an audit encounters unusual execution circumstances, strings can be put in this optional array to add top-level warnings to the LHR. */ runWarnings?: Array; - /** Estimates of how much this audit affects various performance metrics. Values will be in the init of their respective metrics. */ + /** Estimates of how much this audit affects various performance metrics. Values will be in the unit of the respective metrics. */ metricSavings?: MetricSavings; } diff --git a/types/lhr/audit-result.d.ts b/types/lhr/audit-result.d.ts index 2b6c9d0c96f4..0265b6e64f39 100644 --- a/types/lhr/audit-result.d.ts +++ b/types/lhr/audit-result.d.ts @@ -58,7 +58,7 @@ export interface Result { id: string; /** A more detailed description that describes why the audit is important and links to Lighthouse documentation on the audit; markdown links supported. */ description: string; - /** Estimates of how much this audit affects various performance metrics. Values will be in the init of their respective metrics. */ + /** Estimates of how much this audit affects various performance metrics. Values will be in the unit of the respective metrics. */ metricSavings?: MetricSavings; /** A numeric value that has a meaning specific to the audit, e.g. the number of nodes in the DOM or the timestamp of a specific load event. More information can be found in the audit details, if present. */ numericValue?: number; From f824dd5160e473624bb67ea8b6d2e2f639f19667 Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Thu, 20 Apr 2023 13:54:53 -0700 Subject: [PATCH 3/6] sample --- .../fraggle-rock/reports/sample-flow-result.json | 9 +++++++++ core/test/results/sample_v2.json | 3 +++ 2 files changed, 12 insertions(+) diff --git a/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json b/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json index 1cfa67510599..b15ae593a7df 100644 --- a/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json +++ b/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json @@ -1477,6 +1477,9 @@ "wastedMs": 0 }, "isEntityGrouped": true + }, + "metricSavings": { + "TBT": 0 } }, "third-party-facades": { @@ -8679,6 +8682,9 @@ "wastedMs": 0 }, "isEntityGrouped": true + }, + "metricSavings": { + "TBT": 0 } }, "layout-shift-elements": { @@ -17324,6 +17330,9 @@ } ], "isEntityGrouped": true + }, + "metricSavings": { + "TBT": 0 } }, "third-party-facades": { diff --git a/core/test/results/sample_v2.json b/core/test/results/sample_v2.json index 14a5fa547071..6a16ecc58977 100644 --- a/core/test/results/sample_v2.json +++ b/core/test/results/sample_v2.json @@ -2236,6 +2236,9 @@ "wastedMs": 0 }, "isEntityGrouped": true + }, + "metricSavings": { + "TBT": 0 } }, "third-party-facades": { From 0d840d495fc3897823b6dcf4a2f94200e96f1fe1 Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Thu, 20 Apr 2023 15:18:26 -0700 Subject: [PATCH 4/6] response time --- core/audits/server-response-time.js | 7 ++++++- core/audits/third-party-summary.js | 3 --- .../reports/sample-flow-result.json | 21 +++++++++---------- core/test/results/sample_v2.json | 7 ++++--- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/core/audits/server-response-time.js b/core/audits/server-response-time.js index c0df87c657c1..41070d7fb755 100644 --- a/core/audits/server-response-time.js +++ b/core/audits/server-response-time.js @@ -70,10 +70,11 @@ class ServerResponseTime extends Audit { {key: 'responseTime', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnTimeSpent)}, ]; + const overallSavingsMs = Math.max(responseTime - TARGET_MS, 0); const details = Audit.makeOpportunityDetails( headings, [{url: mainResource.url, responseTime}], - {overallSavingsMs: responseTime - TARGET_MS} + {overallSavingsMs} ); return { @@ -82,6 +83,10 @@ class ServerResponseTime extends Audit { score: Number(passed), displayValue, details, + metricSavings: { + FCP: overallSavingsMs, + LCP: overallSavingsMs, + }, }; } } diff --git a/core/audits/third-party-summary.js b/core/audits/third-party-summary.js index 8b7756cfea70..a2e67df5e1e3 100644 --- a/core/audits/third-party-summary.js +++ b/core/audits/third-party-summary.js @@ -252,9 +252,6 @@ class ThirdPartySummary extends Audit { timeInMs: overallSummary.wastedMs, }), details, - metricSavings: { - TBT: overallSummary.wastedMs, - }, }; } } diff --git a/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json b/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json index b15ae593a7df..8894aa71ecfe 100644 --- a/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json +++ b/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json @@ -233,7 +233,11 @@ "responseTime": 19.687999999999988 } ], - "overallSavingsMs": -80.31200000000001 + "overallSavingsMs": 0 + }, + "metricSavings": { + "FCP": 0, + "LCP": 0 } }, "interactive": { @@ -1477,9 +1481,6 @@ "wastedMs": 0 }, "isEntityGrouped": true - }, - "metricSavings": { - "TBT": 0 } }, "third-party-facades": { @@ -8682,9 +8683,6 @@ "wastedMs": 0 }, "isEntityGrouped": true - }, - "metricSavings": { - "TBT": 0 } }, "layout-shift-elements": { @@ -16135,7 +16133,11 @@ "responseTime": 10.263 } ], - "overallSavingsMs": -89.737 + "overallSavingsMs": 0 + }, + "metricSavings": { + "FCP": 0, + "LCP": 0 } }, "interactive": { @@ -17330,9 +17332,6 @@ } ], "isEntityGrouped": true - }, - "metricSavings": { - "TBT": 0 } }, "third-party-facades": { diff --git a/core/test/results/sample_v2.json b/core/test/results/sample_v2.json index 6a16ecc58977..61cd8eea7f3f 100644 --- a/core/test/results/sample_v2.json +++ b/core/test/results/sample_v2.json @@ -337,6 +337,10 @@ } ], "overallSavingsMs": 468.46799999999996 + }, + "metricSavings": { + "FCP": 468.46799999999996, + "LCP": 468.46799999999996 } }, "interactive": { @@ -2236,9 +2240,6 @@ "wastedMs": 0 }, "isEntityGrouped": true - }, - "metricSavings": { - "TBT": 0 } }, "third-party-facades": { From 2adefed68d07ec6011f70917b54896e7ac91900f Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Wed, 26 Apr 2023 13:09:04 -0700 Subject: [PATCH 5/6] move to audit details --- core/audits/audit.js | 1 - core/audits/server-response-time.js | 8 ++++---- types/audit.d.ts | 3 --- types/lhr/audit-details.d.ts | 10 ++++++++++ types/lhr/audit-result.d.ts | 10 +--------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/core/audits/audit.js b/core/audits/audit.js index 4d3ca0d77c5e..f44f617692af 100644 --- a/core/audits/audit.js +++ b/core/audits/audit.js @@ -410,7 +410,6 @@ class Audit { warnings: product.warnings, details: product.details, - metricSavings: product.metricSavings, }; } } diff --git a/core/audits/server-response-time.js b/core/audits/server-response-time.js index 41070d7fb755..a80dde34fa51 100644 --- a/core/audits/server-response-time.js +++ b/core/audits/server-response-time.js @@ -76,6 +76,10 @@ class ServerResponseTime extends Audit { [{url: mainResource.url, responseTime}], {overallSavingsMs} ); + details.metricSavings = { + FCP: overallSavingsMs, + LCP: overallSavingsMs, + }; return { numericValue: responseTime, @@ -83,10 +87,6 @@ class ServerResponseTime extends Audit { score: Number(passed), displayValue, details, - metricSavings: { - FCP: overallSavingsMs, - LCP: overallSavingsMs, - }, }; } } diff --git a/types/audit.d.ts b/types/audit.d.ts index 0fa3cbfdabf9..25ecd139c345 100644 --- a/types/audit.d.ts +++ b/types/audit.d.ts @@ -18,7 +18,6 @@ declare module Audit { export type Result = AuditResult.Result; export type ScoreDisplayMode = AuditResult.ScoreDisplayMode; export type ScoreDisplayModes = AuditResult.ScoreDisplayModes; - export type MetricSavings = AuditResult.MetricSavings; type Context = Util.Immutable<{ /** audit options */ @@ -82,8 +81,6 @@ declare module Audit { details?: AuditDetails; /** If an audit encounters unusual execution circumstances, strings can be put in this optional array to add top-level warnings to the LHR. */ runWarnings?: Array; - /** Estimates of how much this audit affects various performance metrics. Values will be in the unit of the respective metrics. */ - metricSavings?: MetricSavings; } /** The Audit.Product type for audits that do not return a `numericValue`. */ diff --git a/types/lhr/audit-details.d.ts b/types/lhr/audit-details.d.ts index 17611dcf9baf..fc054c6913cf 100644 --- a/types/lhr/audit-details.d.ts +++ b/types/lhr/audit-details.d.ts @@ -15,6 +15,8 @@ interface BaseDetails { overallSavingsBytes?: number; /** Additional information, usually used for including debug or meta information in the LHR */ debugData?: Details.DebugData; + /** Estimates of how much this audit affects various performance metrics. Values will be in the unit of the respective metrics. */ + metricSavings?: Details.MetricSavings; } type Details = @@ -303,6 +305,14 @@ declare module Details { value: number, granularity?: number, } + + interface MetricSavings { + LCP?: number; + FCP?: number; + CLS?: number; + TBT?: number; + INP?: number; + } } export default Details; diff --git a/types/lhr/audit-result.d.ts b/types/lhr/audit-result.d.ts index 0265b6e64f39..48b3146740e4 100644 --- a/types/lhr/audit-result.d.ts +++ b/types/lhr/audit-result.d.ts @@ -24,14 +24,6 @@ interface ScoreDisplayModes { type ScoreDisplayMode = ScoreDisplayModes[keyof ScoreDisplayModes]; -interface MetricSavings { - LCP?: number; - FCP?: number; - CLS?: number; - TBT?: number; - INP?: number; -} - /** Audit result returned in Lighthouse report. All audits offer a description and score of 0-1. */ export interface Result { displayValue?: string; @@ -59,7 +51,7 @@ export interface Result { /** A more detailed description that describes why the audit is important and links to Lighthouse documentation on the audit; markdown links supported. */ description: string; /** Estimates of how much this audit affects various performance metrics. Values will be in the unit of the respective metrics. */ - metricSavings?: MetricSavings; + metricSavings?: AuditDetails.MetricSavings; /** A numeric value that has a meaning specific to the audit, e.g. the number of nodes in the DOM or the timestamp of a specific load event. More information can be found in the audit details, if present. */ numericValue?: number; /** The unit of `numericValue`, used when the consumer wishes to convert numericValue to a display string. */ From d33636f62f5d3c727c57f2f2a5bef704d8c35506 Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Wed, 26 Apr 2023 13:10:25 -0700 Subject: [PATCH 6/6] sample --- .../reports/sample-flow-result.json | 20 +++++++++---------- core/test/results/sample_v2.json | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json b/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json index 8894aa71ecfe..a066dcea3f0b 100644 --- a/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json +++ b/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json @@ -233,11 +233,11 @@ "responseTime": 19.687999999999988 } ], - "overallSavingsMs": 0 - }, - "metricSavings": { - "FCP": 0, - "LCP": 0 + "overallSavingsMs": 0, + "metricSavings": { + "FCP": 0, + "LCP": 0 + } } }, "interactive": { @@ -16133,11 +16133,11 @@ "responseTime": 10.263 } ], - "overallSavingsMs": 0 - }, - "metricSavings": { - "FCP": 0, - "LCP": 0 + "overallSavingsMs": 0, + "metricSavings": { + "FCP": 0, + "LCP": 0 + } } }, "interactive": { diff --git a/core/test/results/sample_v2.json b/core/test/results/sample_v2.json index 61cd8eea7f3f..abc2b28a250d 100644 --- a/core/test/results/sample_v2.json +++ b/core/test/results/sample_v2.json @@ -336,11 +336,11 @@ "responseTime": 568.468 } ], - "overallSavingsMs": 468.46799999999996 - }, - "metricSavings": { - "FCP": 468.46799999999996, - "LCP": 468.46799999999996 + "overallSavingsMs": 468.46799999999996, + "metricSavings": { + "FCP": 468.46799999999996, + "LCP": 468.46799999999996 + } } }, "interactive": {