Here's a simplified example: (defn wat [& {:keys [a b c d e f map-0 map-1 map-2]}] (cond-> "foo" a (str a) b (str b) c (str c) d (str d) e (str e) f (str f) map-0 (cond-> (:a map-0) (str (:a map-0)) (:b map-0) (str (:b map-0)) (:c map-0) (str (:c map-0)) (:d map-0) (str (:d map-0))) map-1 (cond-> (:a map-1) (str (:a map-1)) (:b map-1) (str (:b map-1)) (:c map-1) (str (:c map-1)) (:d map-1) (str (:d map-1))) map-2 (cond-> (:a map-2) (str (:a map-2)) (:b map-2) (str (:b map-2)) (:c map-2) (str (:c map-2)) (:d map-2) (str (:d map-2)))))
On Thursday, July 20, 2017 at 6:36:42 PM UTC-4, Milt Reder wrote: > > Hey Clojurians, > I'm experiencing some odd behavior with cond-> and was wondering if anyone > had any ideas. I was troubleshooting a very slow load time in one of our > projects, and traced it to a web templating library we maintain. One of the > functions in this lib, `cell` takes a *very* long time (about a minute) to > define in Clojure: > > (def valid-align #{:top :middle :bottom}) > > (def align-mdl-class > {:top "mdl-cell--top" > :middle "mdl-cell--middle" > :bottom "mdl-cell--bottom"}) > > (defn cell [& {:keys [align offset order col stretch? > desktop tablet phone > children > id class attr] > :as args}] > (when align (assert (valid-align align))) > (into > [:div > (merge > {:id id > :class (cond-> "mdl-cell" > class (str " " class) > stretch? (str " mdl-cell--stretch") > align (str " " (align-mdl-class align)) > offset (str " mdl-cell--" offset "-offset") > order (str " mdl-cell--" order "-order") > col (str " mdl-cell--" col "-col") > desktop (cond-> > (:col desktop) (str " mdl-cell--" (:col > desktop) "-col-desktop") > (:offset desktop) (str " mdl-cell--" (:offset > desktop) "-offset-desktop") > (:order desktop) (str " mdl-cell--" (:order > desktop) "-order-desktop") > (:hide? desktop) (str " mdl-cell--hide-desktop")) > tablet (cond-> > (:col tablet) (str " mdl-cell--" (:col tablet) > "-col-tablet") > (:offset tablet) (str " mdl-cell--" (:offset > tablet) "-offset-tablet") > (:order tablet) (str " mdl-cell--" (:order > tablet) "-order-tablet") > (:hide? tablet) (str " mdl-cell--hide-tablet")) > phone (cond-> > (:col phone) (str " mdl-cell--" (:col phone) > "-col-phone") > (:offset phone) (str " mdl-cell--" (:offset > phone) "-offset-phone") > (:order phone) (str " mdl-cell--" (:order phone) > "-order-phone") > (:hide? phone) (str " mdl-cell--hide-phone")))} > attr)] > children)) > > > It works fine at runtime, but loading it in Clojure (1.8 or 1.9-alpha17) > takes far longer than I'd expect. Try loading the above code in a repl and > see for yourself. The templating lib is cljc, and both loading and running > it are fine (a couple ms) in cljs. The time taken seems to increase > exponentially with more clauses added to the nested cond->'s near the > bottom in clojure. > > I've rewritten it without cond-> and it works fine, but I was wondering if > anyone could shed light on why this is, and why it isn't an issue in cljs. > > Cheers, > Milt > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.