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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.