4 ms·
JIT compilation cannot perform expensive optimizations by design, it has to be low-overhead. Functional iteration can only be fast when its optimized in to a si
by FrozenVoid 8y ago
JIT compilation cannot perform expensive optimizations by design, it has to be low-overhead.
Functional iteration can only be fast when its optimized in to a simpler form - with JIT and dynamic variables everywhere.
For loop is already the simpler form and is easier for JIT compiler to reason about.
Sure the imperative code is often longer and less cool than a functional one-liner that chains everything to be done, but it has no hidden performance costs and is obvious to read and debug.