Skip to content

Commit

Permalink
clients(lr): fix wrong render-blocking-resources transfer size (#16190)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Sep 19, 2024
1 parent a17f36e commit 0c7c183
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
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
43 changes: 43 additions & 0 deletions core/test/audits/byte-efficiency/render-blocking-resources-test.js
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

0 comments on commit 0c7c183

Please sign in to comment.