Showing posts with label maps. Show all posts
Showing posts with label maps. Show all posts

Thursday, 26 January 2012

Oh, that performance thing...

Sooo, via this fascinating post and confirmed by my own dirty timing efforts, there's another excellent reason to not define structures that naively implement clojure.lang.IFn.

That being, it's really rather slow.

Using an AABB tree-node I've been messing with, extracting a single argument from a node defined with defrecord 106 times takes roughly:

TimeForm
15 ms(:key node)
135 ms(node :key) (that is, implementing IFn using get)
85 ms(let [{:keys [key]} node] ...)

Fascinating stuff. But that's definitely a large enough improvment that I'll be stripping out the implementation of invoke, and be more aggressive promoting ad-hoc maps to records in future! It's hard to say no to an order of magnitude improvement.

Edit: I don't mean that clojure.lang.IFn is necessarily slow, just that it seems the (:key record) form is faster than (get record :key). I'm assuming this is due to directly mapping the former to member access, whilst the latter has to use some combination of additional reflection and the hash map implementation to get the value.