Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(render-blocking-resources): reduce metric savings if LCP is an image #15694

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions core/audits/byte-efficiency/render-blocking-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {NetworkRequest} from '../../lib/network-request.js';
import {ProcessedNavigation} from '../../computed/processed-navigation.js';
import {LoadSimulator} from '../../computed/load-simulator.js';
import {FirstContentfulPaint} from '../../computed/metrics/first-contentful-paint.js';
import {LCPImageRecord} from '../../computed/lcp-image-record.js';


/** @typedef {import('../../lib/dependency-graph/simulator/simulator').Simulator} Simulator */
/** @typedef {import('../../lib/dependency-graph/base-node.js').Node} Node */
Expand Down Expand Up @@ -125,7 +127,7 @@ class RenderBlockingResources extends Audit {
/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {Promise<{wastedMs: number, results: Array<{url: string, totalBytes: number, wastedMs: number}>}>}
* @return {Promise<{fcpWastedMs: number, lcpWastedMs: number, results: Array<{url: string, totalBytes: number, wastedMs: number}>}>}
*/
static async computeResults(artifacts, context) {
const gatherContext = artifacts.GatherContext;
Expand Down Expand Up @@ -179,18 +181,21 @@ class RenderBlockingResources extends Audit {
}

if (!results.length) {
return {results, wastedMs: 0};
return {results, fcpWastedMs: 0, lcpWastedMs: 0};
}

const wastedMs = RenderBlockingResources.estimateSavingsWithGraphs(
const fcpWastedMs = RenderBlockingResources.estimateSavingsWithGraphs(
simulator,
fcpSimulation.optimisticGraph,
deferredNodeIds,
wastedCssBytes,
artifacts.Stacks
);

return {results, wastedMs};
const lcpRecord = await LCPImageRecord.request(metricComputationData, context);

// In most cases if the LCP is an image, render blocking resources don't affect LCP. For these cases we should reduce its impact.
return {results, fcpWastedMs, lcpWastedMs: lcpRecord ? 0 : fcpWastedMs};
adrianaixba marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -276,11 +281,12 @@ class RenderBlockingResources extends Audit {
* @return {Promise<LH.Audit.Product>}
*/
static async audit(artifacts, context) {
const {results, wastedMs} = await RenderBlockingResources.computeResults(artifacts, context);
const {results, fcpWastedMs, lcpWastedMs} =
await RenderBlockingResources.computeResults(artifacts, context);

let displayValue;
if (results.length > 0) {
displayValue = str_(i18n.UIStrings.displayValueMsSavings, {wastedMs});
displayValue = str_(i18n.UIStrings.displayValueMsSavings, {wastedMs: fcpWastedMs});
}

/** @type {LH.Audit.Details.Opportunity['headings']} */
Expand All @@ -291,15 +297,15 @@ class RenderBlockingResources extends Audit {
];

const details = Audit.makeOpportunityDetails(headings, results,
{overallSavingsMs: wastedMs});
{overallSavingsMs: fcpWastedMs});

return {
displayValue,
score: results.length ? 0 : 1,
numericValue: wastedMs,
numericValue: fcpWastedMs,
numericUnit: 'millisecond',
details,
metricSavings: {FCP: wastedMs, LCP: wastedMs},
metricSavings: {FCP: fcpWastedMs, LCP: lcpWastedMs},
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Render blocking resources audit', () => {
// it look like Montserrat starts after Fira Sans finishes. It would be preferred
// if eventual simulation improvements list Montserrat here as well.
]);
expect(result.metricSavings).toEqual({FCP: 469, LCP: 469});
expect(result.metricSavings).toEqual({FCP: 469, LCP: 0});
});

describe('#estimateSavingsWithGraphs', () => {
Expand Down
Loading