Faster Math in Clojure 1.7

Clojure.jpg

Clojure is forced to use reflection in a lot of cases simply because there is no type system in place, and when you're iterating on a sequence of elements, you have to ask each one Hey... what are you? and then see if you can do something with that. It's understandable, and it's the point of adding type hinting in the function signatures, but it hurts when you have Java auto-boxing int to Integer, and then trying to do math on those values.

It slows simple math way down - and that's not typically something you want to slow down.

Thankfully, in Clojure 1.7, there's a new dynamic variable that will check all the math to make sure that it's not boxed:

  (set! *unchecked-math* :warn-on-boxed)

and then for the scope of that definition, it'll check to see that all the math is not boxed. This can help identify the source of a performance issue without the painful profiling.

Great to see... now if Storm could just be on 1.7...