3 ms·
Map was quadratic before?! It seems like it would take deliberate effort to make it anything other than linear.
by Xichekolas 18y ago
Map was quadratic before?! It seems like it would take deliberate effort to make it anything other than linear.
- nostrademons 18y ago$.map has an interesting quirk in its spec: it flattens returned arrays into the result. This was implemented by calling concat() with each result, but concat creates a new array for its return value. So each iteration was creating a new array and copying over the previous values, which makes for a quadratic runtime in most JS runtimes. (Curiously, in the benchmarks folks did in the Reddit thread, it looked like Firefox was not quadratic - which implies that Firefox either has some clever optimizations going on or does crazy things with concat().)