Closed maxcountryman closed 10 years ago
Oh interesting, is that due to destructuring and the call to get
?
Yeah, you gotta create a seq, call first, call rest, then call apply instead of assoc directly, which means boxing up args as an arraylist, then wrapping that in a seq, etc... ordinarily I wouldn't mind but this code was, if I recall, kinda performance-sensitive. We could totally drop a (defn update) in utils though!
Geez yeah, quite a bit faster it turns out:
user=> (time (dotimes [_ 1e8] (assoc {} :history (conj (:history {}) :a))))
"Elapsed time: 3876.263 msecs"
nil
user=> (time (dotimes [_ 1e8] (update-in {} [:history] conj :a)))
"Elapsed time: 34815.863 msecs"
nil
Assoc is actually significantly faster than update-in, so I think I'd like to keep this particular case as is.