Skip to content

Commit

Permalink
core: add metric savings to audit result (#14997)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored May 10, 2023
1 parent 3d78192 commit 3a0c62d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/audits/server-response-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ 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}
);
details.metricSavings = {
FCP: overallSavingsMs,
LCP: overallSavingsMs,
};

return {
numericValue: responseTime,
Expand Down
12 changes: 10 additions & 2 deletions core/test/fixtures/fraggle-rock/reports/sample-flow-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@
"responseTime": 19.687999999999988
}
],
"overallSavingsMs": -80.31200000000001
"overallSavingsMs": 0,
"metricSavings": {
"FCP": 0,
"LCP": 0
}
}
},
"interactive": {
Expand Down Expand Up @@ -16685,7 +16689,11 @@
"responseTime": 10.263
}
],
"overallSavingsMs": -89.737
"overallSavingsMs": 0,
"metricSavings": {
"FCP": 0,
"LCP": 0
}
}
},
"interactive": {
Expand Down
6 changes: 5 additions & 1 deletion core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@
"responseTime": 568.468
}
],
"overallSavingsMs": 468.46799999999996
"overallSavingsMs": 468.46799999999996,
"metricSavings": {
"FCP": 468.46799999999996,
"LCP": 468.46799999999996
}
}
},
"interactive": {
Expand Down
10 changes: 10 additions & 0 deletions types/lhr/audit-details.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
2 changes: 2 additions & 0 deletions types/lhr/audit-result.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 unit of the respective metrics. */
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. */
Expand Down

0 comments on commit 3a0c62d

Please sign in to comment.