Skip to content

Commit 35eaea6

Browse files
committed
core(audits): prevent yield-bounded tasks from being reported as long tasks
The original issue reported that both Total Blocking Time (TBT) and JavaScript execution time were being artificially inflated during simulated mobile throttling. While the Total CPU Time math is technically correct across the whole page, the simulated long tasks were appearing in the `long-tasks` audit table. This commit ensures the `long-tasks` audit respects the original unthrottled duration of tasks bounded by `scheduler.yield` or `scheduler.postTask`, preventing them from falsely polluting the list of input delay contributors. Fixes #16183
1 parent 8cc747c commit 35eaea6

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

cli/test/smokehouse/test-definitions/lantern-scheduler-apis.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ const expectations = [
2424
'total-blocking-time': {
2525
numericValue: '<=100',
2626
},
27+
'long-tasks': {
28+
details: {
29+
items: {
30+
length: 0,
31+
},
32+
},
33+
},
2734
},
2835
},
2936
},
@@ -35,6 +42,13 @@ const expectations = [
3542
'total-blocking-time': {
3643
numericValue: '<=100',
3744
},
45+
'long-tasks': {
46+
details: {
47+
items: {
48+
length: 0,
49+
},
50+
},
51+
},
3852
},
3953
},
4054
},

core/audits/long-tasks.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,21 @@ class LongTasks extends Audit {
199199
const simulation = simulator.simulate(pageGraph, {label: 'long-tasks-diagnostic'});
200200
for (const [node, timing] of simulation.nodeTimings.entries()) {
201201
if (node.type !== 'cpu') continue;
202-
taskTimingsByEvent.set(node.event, timing);
202+
203+
let duration = timing.duration;
204+
// @ts-expect-error - childEvents is not typed
205+
const isYieldBounded = node.childEvents?.some(e => {
206+
return e.name === 'ScheduleYieldContinuation' ||
207+
e.name === 'RunYieldContinuation' ||
208+
e.name === 'SchedulePostTaskCallback' ||
209+
e.name === 'RunPostTaskCallback';
210+
});
211+
212+
if (isYieldBounded) {
213+
duration = node.duration / 1000;
214+
}
215+
216+
taskTimingsByEvent.set(node.event, {...timing, duration});
203217
}
204218
}
205219

0 commit comments

Comments
 (0)