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

clients(lr): fix wrong render-blocking-resources transfer size #16190

Merged
merged 8 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions core/audits/byte-efficiency/render-blocking-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
/**
* Given a simulation's nodeTimings, return an object with the nodes/timing keyed by network URL
* @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
* @return {Map<string, {node: LH.Gatherer.Simulation.GraphNode, nodeTiming: LH.Gatherer.Simulation.NodeTiming}>}
* @return {Map<string, {node: LH.Gatherer.Simulation.GraphNetworkNode, nodeTiming: LH.Gatherer.Simulation.NodeTiming}>}
*/
function getNodesAndTimingByRequestId(nodeTimings) {
/** @type {Map<string, {node: LH.Gatherer.Simulation.GraphNode, nodeTiming: LH.Gatherer.Simulation.NodeTiming}>} */
/** @type {Map<string, {node: LH.Gatherer.Simulation.GraphNetworkNode, nodeTiming: LH.Gatherer.Simulation.NodeTiming}>} */
const requestIdToNode = new Map();

for (const [node, nodeTiming] of nodeTimings) {
Expand Down Expand Up @@ -169,7 +169,7 @@ class RenderBlockingResources extends Audit {

results.push({
url: resource.args.data.url,
totalBytes: resource.args.data.encodedDataLength,
totalBytes: node.request.transferSize,
wastedMs,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const {Simulator} = Lantern.Simulation;

const trace = readJson('../../fixtures/artifacts/render-blocking/trace.json', import.meta);
const devtoolsLog = readJson('../../fixtures/artifacts/render-blocking/devtoolslog.json', import.meta);
const lrTrace = readJson('../../fixtures/artifacts/lr/trace.json.gz', import.meta);
const lrDevtoolsLog = readJson('../../fixtures/artifacts/lr/devtoolslog.json.gz', import.meta);

const mobileSlow4G = constants.throttling.mobileSlow4G;

Expand All @@ -38,6 +40,47 @@ describe('Render blocking resources audit', () => {
assert.deepStrictEqual(result.metricSavings, {FCP: 300, LCP: 0});
});

describe('Lightrider', () => {
before(() => {
global.isLightrider = true;
});

after(() => {
global.isLightrider = undefined;
});

it('considers X-TotalFetchedSize in its reported transfer size', async () => {
// TODO(15841): The trace backend knows nothing of Lantern.
if (process.env.INTERNAL_LANTERN_USE_TRACE !== undefined) {
return;
}

const artifacts = {
URL: getURLArtifactFromDevtoolsLog(lrDevtoolsLog),
GatherContext: {gatherMode: 'navigation'},
traces: {defaultPass: lrTrace},
devtoolsLogs: {defaultPass: lrDevtoolsLog},
Stacks: [],
};

const settings = {throttlingMethod: 'simulate', throttling: mobileSlow4G};
const computedCache = new Map();
const result = await RenderBlockingResourcesAudit.audit(artifacts, {settings, computedCache});
expect(result.details.items).toMatchInlineSnapshot(`
Array [
Object {
"totalBytes": 128188,
"url": "https://www.llentab.cz/wp-content/uploads/fusion-styles/715df3f482419a9ed822189df6e57839.min.css?ver=3.11.10",
"wastedMs": 750,
},
]
`);
assert.equal(result.score, 0);
assert.equal(result.numericValue, 0);
assert.deepStrictEqual(result.metricSavings, {FCP: 0, LCP: 0});
});
});

it('evaluates correct wastedMs when LCP is text', async () => {
const textLcpTrace = JSON.parse(JSON.stringify(trace));

Expand Down
Binary file not shown.
Binary file added core/test/fixtures/artifacts/lr/trace.json.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4496,7 +4496,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/unknown404.css?delay=200",
"totalBytes": 0,
"totalBytes": 235,
"wastedMs": 881
},
{
Expand All @@ -4516,7 +4516,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/fcp-delayer.js?delay=5000",
"totalBytes": 0,
"totalBytes": 249,
"wastedMs": 881
}
],
Expand Down
Loading