perf(tooling): avoid a second large-array spread in trace summarising

The longest-task calculation spread every recorded task into Math.max, which
overflowed the call stack on traces carrying hundreds of thousands of tasks —
the same failure already fixed for collecting trace events.
This commit is contained in:
Bohdan Triapitsyn
2026-08-03 19:14:45 +03:00
parent 51d814307f
commit e53a8a52cf
+3 -1
View File
@@ -80,7 +80,9 @@ export const summarizeLongTasks = (traceEvents, thresholdMs = 50) => {
taskCount: durations.length,
longTaskCount: long.length,
longTaskTotalMs: round(long.reduce((total, duration) => total + duration, 0)),
longestTaskMs: round(Math.max(0, ...durations)),
// Spreading a large array into Math.max overflows the call stack; a trace
// can easily carry hundreds of thousands of tasks.
longestTaskMs: round(durations.reduce((max, duration) => Math.max(max, duration), 0)),
taskP95Ms: percentile(durations, 0.95),
taskP99Ms: percentile(durations, 0.99),
}