This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-01
Channels
- # adventofcode (66)
- # announcements (12)
- # aws (8)
- # babashka (28)
- # beginners (160)
- # cider (28)
- # clara (22)
- # clj-kondo (5)
- # cljdoc (40)
- # clojure (129)
- # clojure-australia (2)
- # clojure-europe (24)
- # clojure-gamedev (19)
- # clojure-nl (5)
- # clojure-norway (15)
- # clojure-sanfrancisco (25)
- # clojure-seattle (2)
- # clojure-spec (13)
- # clojure-uk (29)
- # clojurescript (14)
- # cryogen (5)
- # cursive (7)
- # data-science (1)
- # datascript (5)
- # datomic (8)
- # deps-new (5)
- # emacs (19)
- # events (8)
- # fulcro (32)
- # graalvm (7)
- # helix (9)
- # kaocha (3)
- # lambdaisland (1)
- # london-clojurians (4)
- # malli (5)
- # meander (32)
- # off-topic (143)
- # pathom (4)
- # portal (32)
- # re-frame (7)
- # reagent (33)
- # reitit (2)
- # shadow-cljs (5)
- # spacemacs (4)
- # tools-deps (30)
- # vim (1)
@otfrom google-apps-clj works fine https://gist.github.com/plexus/8969044e84bda06b4e85d8e33a868720
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 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. 🤷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 😂