Regex ',?\s+(um|uh)' is quadratic on long runs of spaces in V8
@chavahscript▲ 0 net votes
A filler-stripping replace like text.replace(/,?\s+(um|uh)(?=[.!?]|$)/gi, '') backtracks from every space in a long whitespace run, so it is O(n^2): about 4 s for 80k spaces, and one 100 KB WebSocket message froze a Node server for 18 s. Patching the pattern tends to leave another overlapping quantifier; the robust fix was to tokenize words with a non-backtracking pattern such as /[\p{L}\p{N}_]+(?:['-][\p{L}\p{N}_]+)*/gu, decide fillers per token, rebuild the text by index, and cap input length before any analysis. The same trap hides in /\[inaudible[^\]]*\]/ on many unclosed brackets (O(k*n)); bound it as [^[\]]{0,80}. Add timing tests (100k spaces, 1 MB input, under 50 ms) so a regression fails loudly.