Good Morning!
Good morning!
@otfrom google-apps-clj works fine https://gist.github.com/plexus/8969044e84bda06b4e85d8e33a868720
awesome. thx!
moin moin
godmorgen
awesome. thx!
morning
Moin!
morning ... mood
Morning! Welcome to join the London Clojurians meetup tonight, where'll be showing some internals of babashka and sci. https://www.meetup.com/London-Clojurians/events/274014078/
Good morning!
The view from my shower :rolling_on_the_floor_laughing: 🙈
I call that a snow-day. Grab a snowboard/skis and hit those slopes!
I revisited some code in sci and thought: what the hell did I do here. Perf gain my ass. Then I checked it:
user> (time (dotimes [i 1000000] (let [expr '(1 2 3) cond (first expr) expr (rest expr) then (first expr) expr (rest expr) else (first expr)] [cond then else])))
"Elapsed time: 119.671576 msecs"
nil
user> (time (dotimes [i 1000000] (let [[cond then else] '(1 2 3)] [cond then else])))
"Elapsed time: 744.034037 msecs"
nil
Yeah, indeed, that's a perf gain. Sequential destructuring costs more than manually writing things with first and rest. 🤷Morning
I thought destructuring expanded to the same thing
Destructuring expands to nth
calls on the vector
user=> (destructure '[[cond then else] '(1 2 3)])
[vec__34112 (quote (1 2 3)) cond (clojure.core/nth vec__34112 0 nil) then (clojure.core/nth vec__34112 1 nil) else (clojure.core/nth vec__34112 2 nil)]
huh, no, it expands to nth
calls on the thing you destructure on, and nth for lists isn't so perfect for this since that's an O(n) operation
user=> (time (dotimes [i 1000000] (let [[cond then else] [1 2 3]] [cond then else])))
"Elapsed time: 65.380112 msecs"
nil
user=> (time (dotimes [i 1000000] (let [[cond then else] (list 1 2 3)] [cond then else])))
"Elapsed time: 1181.079782 msecs"
But the cost of turning a list into a vector should also be taken into account:
user=> (time (dotimes [i 1000000] (let [[cond then else] (vec (list 1 2 3))] [cond then else])))
"Elapsed time: 572.364397 msecs"
so all in all, doing first + rest might be the optimal destructuring for listsSo it has to reiterate the list each time. Interesting. That seems like an opportunity for destructure to get smarter.
Although, I'm a terrible human being who parses the destructure output: https://github.com/juxt/clip/blob/eb5bef08d9ddc4d39c9084ab123b02b90f9b177a/src/juxt/clip/core.cljc#L146 😂