Fork me on GitHub
#clojurescript
<
2021-07-03
>
borkdude21:07:47

Why is the upper expression roughly twice as fast in chrome?

(time (dotimes [i 10000000] ((fn [_]) :foo)))
(time (let [x (fn [_])] (dotimes [i 10000000] (x :foo))))
I ran this in http://app.klipse.tech/

jkxyz21:07:59

I have very little knowledge of compiler optimizations, but maybe because in the first expression, the closure of the immediately-invoked function is the same as the caller, so the JS compiler knows it can elide code which would modify the stack before entering the function

Aron07:07:57

don't microbenchmark javascript jit compilers