Skip to content

Commit

Permalink
core: remove relevant audits lists from config (#15878)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored Mar 27, 2024
1 parent fc7dc87 commit d8ccf70
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 255 deletions.
11 changes: 5 additions & 6 deletions core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import * as LH from '../../types/lh.js';
import * as constants from './constants.js';
import * as i18n from '../lib/i18n/i18n.js';
import {metricsToAudits} from './metrics-to-audits.js';

const UIStrings = {
/** Title of the Performance category of audits. Equivalent to 'Web performance', this term is inclusive of all web page speed and loading optimization topics. Also used as a label of a score gauge; try to limit to 20 characters. */
Expand Down Expand Up @@ -429,12 +428,12 @@ const defaultConfig = {
title: str_(UIStrings.performanceCategoryTitle),
supportedModes: ['navigation', 'timespan', 'snapshot'],
auditRefs: [
{id: 'first-contentful-paint', weight: 10, group: 'metrics', acronym: 'FCP', relevantAudits: metricsToAudits.fcpRelevantAudits},
{id: 'largest-contentful-paint', weight: 25, group: 'metrics', acronym: 'LCP', relevantAudits: metricsToAudits.lcpRelevantAudits},
{id: 'total-blocking-time', weight: 30, group: 'metrics', acronym: 'TBT', relevantAudits: metricsToAudits.tbtRelevantAudits},
{id: 'cumulative-layout-shift', weight: 25, group: 'metrics', acronym: 'CLS', relevantAudits: metricsToAudits.clsRelevantAudits},
{id: 'first-contentful-paint', weight: 10, group: 'metrics', acronym: 'FCP'},
{id: 'largest-contentful-paint', weight: 25, group: 'metrics', acronym: 'LCP'},
{id: 'total-blocking-time', weight: 30, group: 'metrics', acronym: 'TBT'},
{id: 'cumulative-layout-shift', weight: 25, group: 'metrics', acronym: 'CLS'},
{id: 'speed-index', weight: 10, group: 'metrics', acronym: 'SI'},
{id: 'interaction-to-next-paint', weight: 0, group: 'metrics', acronym: 'INP', relevantAudits: metricsToAudits.inpRelevantAudits},
{id: 'interaction-to-next-paint', weight: 0, group: 'metrics', acronym: 'INP'},

// These are our "invisible" metrics. Not displayed, but still in the LHR.
{id: 'interactive', weight: 0, group: 'hidden', acronym: 'TTI'},
Expand Down
60 changes: 0 additions & 60 deletions core/config/metrics-to-audits.js

This file was deleted.

33 changes: 33 additions & 0 deletions core/lib/lighthouse-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,39 @@ function upgradeLhrForCompatibility(lhr) {
}
}

if (majorVersion < 12 && perfCategory) {
/** @type {Map<string, string[]>} */
const metricRelevanceMap = new Map();

for (const auditRef of perfCategory.auditRefs) {
/** @type {string[]|undefined} */
// @ts-expect-error Removed in v12
const relevantAudits = auditRef.relevantAudits;
if (!relevantAudits || !auditRef.acronym) continue;

for (const auditId of relevantAudits) {
const acronyms = metricRelevanceMap.get(auditId) || [];
acronyms.push(auditRef.acronym);
metricRelevanceMap.set(auditId, acronyms);
}
}

for (const [auditId, acronyms] of metricRelevanceMap) {
if (!acronyms.length) continue;

const audit = lhr.audits[auditId];
if (!audit) continue;

// Old versions can still define metric savings, let's not mess with it.
if (audit.metricSavings) continue;

audit.metricSavings = {};
for (const acronym of acronyms) {
audit.metricSavings[acronym] = 0;
}
}
}

// Add some minimal stuff so older reports still work.
if (!lhr.environment) {
lhr.environment = {
Expand Down
136 changes: 11 additions & 125 deletions core/test/fixtures/user-flows/reports/sample-flow-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -3832,72 +3832,25 @@
"id": "first-contentful-paint",
"weight": 10,
"group": "metrics",
"acronym": "FCP",
"relevantAudits": [
"server-response-time",
"render-blocking-resources",
"redirects",
"critical-request-chains",
"uses-text-compression",
"uses-rel-preconnect",
"font-display",
"unminified-javascript",
"unminified-css",
"unused-css-rules"
]
"acronym": "FCP"
},
{
"id": "largest-contentful-paint",
"weight": 25,
"group": "metrics",
"acronym": "LCP",
"relevantAudits": [
"server-response-time",
"render-blocking-resources",
"redirects",
"critical-request-chains",
"uses-text-compression",
"uses-rel-preconnect",
"font-display",
"unminified-javascript",
"unminified-css",
"unused-css-rules",
"largest-contentful-paint-element",
"prioritize-lcp-image",
"unused-javascript",
"efficient-animated-content",
"total-byte-weight",
"lcp-lazy-loaded"
]
"acronym": "LCP"
},
{
"id": "total-blocking-time",
"weight": 30,
"group": "metrics",
"acronym": "TBT",
"relevantAudits": [
"long-tasks",
"third-party-summary",
"third-party-facades",
"bootup-time",
"mainthread-work-breakdown",
"dom-size",
"duplicated-javascript",
"legacy-javascript",
"viewport"
]
"acronym": "TBT"
},
{
"id": "cumulative-layout-shift",
"weight": 25,
"group": "metrics",
"acronym": "CLS",
"relevantAudits": [
"layout-shift-elements",
"layout-shifts",
"non-composited-animations",
"unsized-images"
]
"acronym": "CLS"
},
{
"id": "speed-index",
Expand Down Expand Up @@ -10935,39 +10888,19 @@
"id": "total-blocking-time",
"weight": 30,
"group": "metrics",
"acronym": "TBT",
"relevantAudits": [
"long-tasks",
"third-party-summary",
"third-party-facades",
"bootup-time",
"mainthread-work-breakdown",
"dom-size",
"duplicated-javascript",
"legacy-javascript",
"viewport"
]
"acronym": "TBT"
},
{
"id": "cumulative-layout-shift",
"weight": 25,
"group": "metrics",
"acronym": "CLS",
"relevantAudits": [
"layout-shift-elements",
"layout-shifts",
"non-composited-animations",
"unsized-images"
]
"acronym": "CLS"
},
{
"id": "interaction-to-next-paint",
"weight": 0,
"group": "metrics",
"acronym": "INP",
"relevantAudits": [
"work-during-interaction"
]
"acronym": "INP"
},
{
"id": "uses-responsive-images",
Expand Down Expand Up @@ -21826,72 +21759,25 @@
"id": "first-contentful-paint",
"weight": 10,
"group": "metrics",
"acronym": "FCP",
"relevantAudits": [
"server-response-time",
"render-blocking-resources",
"redirects",
"critical-request-chains",
"uses-text-compression",
"uses-rel-preconnect",
"font-display",
"unminified-javascript",
"unminified-css",
"unused-css-rules"
]
"acronym": "FCP"
},
{
"id": "largest-contentful-paint",
"weight": 25,
"group": "metrics",
"acronym": "LCP",
"relevantAudits": [
"server-response-time",
"render-blocking-resources",
"redirects",
"critical-request-chains",
"uses-text-compression",
"uses-rel-preconnect",
"font-display",
"unminified-javascript",
"unminified-css",
"unused-css-rules",
"largest-contentful-paint-element",
"prioritize-lcp-image",
"unused-javascript",
"efficient-animated-content",
"total-byte-weight",
"lcp-lazy-loaded"
]
"acronym": "LCP"
},
{
"id": "total-blocking-time",
"weight": 30,
"group": "metrics",
"acronym": "TBT",
"relevantAudits": [
"long-tasks",
"third-party-summary",
"third-party-facades",
"bootup-time",
"mainthread-work-breakdown",
"dom-size",
"duplicated-javascript",
"legacy-javascript",
"viewport"
]
"acronym": "TBT"
},
{
"id": "cumulative-layout-shift",
"weight": 25,
"group": "metrics",
"acronym": "CLS",
"relevantAudits": [
"layout-shift-elements",
"layout-shifts",
"non-composited-animations",
"unsized-images"
]
"acronym": "CLS"
},
{
"id": "speed-index",
Expand Down
30 changes: 30 additions & 0 deletions core/test/lib/lighthouse-compatibility-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,34 @@ describe('backward compatibility', () => {
assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
assert.strictEqual(preparedResult.audits['third-party-summary'].details.isEntityGrouped, true);
});

it('uses old metric relevance lists to backfill metric savings', () => {
const clonedSampleResult = cloneLhr(sampleResult);

clonedSampleResult.lighthouseVersion = '11.7.0';

for (const audit of Object.values(clonedSampleResult.audits)) {
// Keep metric savings explicit on this audit
if (audit.id === 'server-response-time') continue;

if (audit.metricSavings) {
delete audit.metricSavings;
}
}

const lcpAuditRef = clonedSampleResult.categories['performance'].auditRefs
.find(a => a.id === 'largest-contentful-paint');
lcpAuditRef.relevantAudits = ['render-blocking-resources'];

// Original audit results should be restored.
const preparedResult = upgradeLhr(clonedSampleResult);
assert.deepStrictEqual(
preparedResult.audits['render-blocking-resources'].metricSavings,
{LCP: 0}
);
assert.deepStrictEqual(
preparedResult.audits['server-response-time'].metricSavings,
{LCP: 450, FCP: 450}
);
});
});
Loading

0 comments on commit d8ccf70

Please sign in to comment.