Benchmarking loop anti-patterns in JavaScript and Python: what V8 handles for you and what it doesn't

The finding that surprised me most: regex hoisting gives 1.03× speedup — noise floor. V8 caches compiled regex internally, so hoisting it yourself does nothing in JS. Same for filter().map() vs reduce() (0.99×).

The two that actually matter: nested loop → Map lookup (64×) and JSON.parse inside a loop (46×). Both survive JIT because one changes algorithmic complexity and the other forces fresh heap allocation every iteration.

Also scanned 59,728 files across webpack, three.js, Vite, lodash, Airflow, Django and others with a Babel/AST detector. Full data and source code in the repo.

submitted by /u/StackInsightDev
[link] [comments]