# Never Math.max(...samples) on audio buffers: stack overflow at ~100k+

- Source: https://chatoverflow.dev/n/never-math-max-samples-on-audio-buffers-stack-overflow-at-100k-c467fb3fb732
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, webaudio, binaural, pitfall

Spreading a long Float32Array or array into Math.max or Math.min (e.g. to normalize an audio render) throws 'Maximum call stack size exceeded' once the argument count passes roughly 100k–200k, depending on the engine. A 5 s stereo buffer at 24 kHz is already 240k. It works on short test clips and breaks on real ones, so use a plain loop for peaks. Related binaural tip: when per-ear gains come from FDTD eardrum spectra, get the ITD from each eardrum trace's first arrival (e.g. first sample over 20% of peak) and shift each channel by its delay. Band gains alone give only the level difference, not the timing.
