diff --git a/core/computed/tbt-impact-tasks.js b/core/computed/tbt-impact-tasks.js index 279b0fcb8810..0d5a9ab636b7 100644 --- a/core/computed/tbt-impact-tasks.js +++ b/core/computed/tbt-impact-tasks.js @@ -87,9 +87,12 @@ class TBTImpactTasks { tbtImpactTasks.push({ ...task, - tbtImpact, - selfTbtImpact, - selfBlockingTime, + // Floating point numbers are not perfectly precise, so the subtraction operations above + // can sometimes output negative numbers close to 0 here. To prevent potentially confusing + // output we should bump those values to 0. + tbtImpact: Math.max(tbtImpact, 0), + selfTbtImpact: Math.max(selfTbtImpact, 0), + selfBlockingTime: Math.max(selfBlockingTime, 0), }); } diff --git a/core/test/computed/tbt-impact-tasks-test.js b/core/test/computed/tbt-impact-tasks-test.js index f7212f4c7e61..3a2d9c8c79d1 100644 --- a/core/test/computed/tbt-impact-tasks-test.js +++ b/core/test/computed/tbt-impact-tasks-test.js @@ -248,8 +248,7 @@ describe('TBTImpactTasks', () => { }; const tasks = await TBTImpactTasks.request(metricComputationData, context); - // Should be >= 0 but provide some wiggle room for double precision - expect(tasks.every(t => t.selfTbtImpact >= -0.00001)).toBeTruthy(); + expect(tasks.every(t => t.selfTbtImpact >= 0)).toBeTruthy(); const tasksImpactingTbt = tasks.filter(t => t.tbtImpact); expect(tasksImpactingTbt.length).toMatchInlineSnapshot(`7374`); @@ -299,8 +298,7 @@ describe('TBTImpactTasks', () => { const tasks = await TBTImpactTasks.request(metricComputationData, context); - // Should be >= 0 but provide some wiggle room for double precision - expect(tasks.every(t => t.selfTbtImpact >= -0.00001)).toBeTruthy(); + expect(tasks.every(t => t.selfTbtImpact >= 0)).toBeTruthy(); const tasksImpactingTbt = tasks.filter(t => t.tbtImpact); expect(tasksImpactingTbt.length).toMatchInlineSnapshot(`1722`);