Bug Description
Array.min() and Array.max() in expressions throw Maximum call stack size exceeded for an array of about 125,000 numbers or more.
Both functions call Math.min(...value) / Math.max(...value), which passes every element of the array as a separate function argument. V8 (and QuickJS) put those arguments on the stack, so a large enough array overflows it. sum() and average() use reduce and work on the same arrays.
The same code is in packages/workflow/src/extensions/array-extensions.ts and its mirror in @n8n/expression-runtime.
To Reproduce
- Add a Set (Edit Fields) node with an expression such as
{{ Array.from({ length: 200000 }, (_, i) => i).max() }}, or call.min()/.max()on a large numeric array from an earlier node (e.g.{{ $json.prices.max() }}with 200,000 prices). - Execute the node.
- The expression fails with
Maximum call stack size exceeded.
Minimal Node reproduction of the same call:
node -e 'console.log(Math.max(...new Array(200000).fill(1)))'
# RangeError: Maximum call stack size exceeded
Expected behavior
199999, as for smaller arrays. on the same array already works.