This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-29
Channels
- # admin-announcements (1)
- # aws (10)
- # beginners (76)
- # boot (53)
- # braid-chat (1)
- # cider (80)
- # cljs-edn (3)
- # clojure (65)
- # clojure-belgium (2)
- # clojure-gamedev (2)
- # clojure-nl (3)
- # clojure-poland (1)
- # clojure-russia (39)
- # clojure-uk (14)
- # clojurescript (91)
- # cursive (62)
- # datascript (1)
- # datomic (9)
- # dirac (34)
- # emacs (25)
- # error-message-catalog (8)
- # events (1)
- # hoplon (88)
- # instaparse (1)
- # jobs (2)
- # jobs-discuss (6)
- # lein-figwheel (7)
- # luminus (43)
- # mount (5)
- # off-topic (7)
- # om (28)
- # onyx (61)
- # planck (4)
- # re-frame (27)
- # reagent (3)
- # remote-jobs (2)
- # spacemacs (3)
- # untangled (136)
@nidu, regarding compilation 512 MB: š®! (Sorry, I don't have any constructive advice. I learned about uberjars (including ClojureScript) so that I could build my Clojure+ClojureScript app on my beefy laptop and scp the standalone JAR to a Raspberry Pi, because the thought of compiling on that was so horrifying.)
@fasiha: yeah, scp is a very convenient option (which i use as well eventually). I just tried to start app on dedicated server, stumbled upon multiple obstacles and had to recompile the app a lot of times. Transfering an entire uberjar each time would be cumbersome with limited traffic. Moreover i serve static independently of jar files so i still can make uberjar on server and transfer just js file.
(That reminds me, I should see if rsync can speed up transfer, I'm assuming for small changes the majority of the JAR is the same. But the time I spend copying is tiny compared to how long my laptop spends building the JAR and how long my target spends loading itā¦ š the joys of lightweight environments)
No, it's not static, i just server static files with nginx so i just put resources separated from jar.
@fasiha, @nidu: I rsync my uberjars and see a significant speedup. Large parts of the uberjar are the same as before, so rsync is fairly speedy.
hi guys I have a problem regarding cljs build optimization. I have this eval-str function:
(defn eval-str
[s]
(if-not (string? s)
(warn "s is not a string")
(try
(cljs.js/eval-str
(empty-state) s nil
{:eval js-eval}
(fn [result] (:value result)))
(catch js/Error e
(debug "[eval-str]" e)))))
Same function, when I run in dev mode ( optimization ;none
) it works just fine, but when in :advanced
mode, it returns nil. What could go wrong here ?you're using bootstrapped clojurescript? I don't think that works under :advanced compilation
I don't really use boostrapped clojurescript, I do store cljs data structure as string in localcache
I don't know if there is any other way, I may try transit read and write instead. Do you have any suggestions ?
@thheller:, @plexus thanks you both. transit does seem to work. I will keep read-string in mind. It's good to know, thanks guys
No reference. This is about channels that get a single value put into them, which causes something to terminate. I wondered if I should bother closing them.
@nxqd: google closure is in charge of :optimizations :advanced
and in order for it to work it imposes some restrictions on the generated javascript. one of them is that you donāt use eval
(which makes static analysis impossible)
if you are not evaluating code but rather reading in data structures, use read-string
or transit as suggested
@nxqd @thheller @plexus: here's a caveat I found with transit: if your data was generated by a non-transit JSON lib, and has strings that start with ~
: tilde is a special character to transit and it won't work right:
=> (t/read (t/reader :json) "\"hi there\"")
; "hi there"
=> (t/read (t/reader :json) "\"~hi there\"")
; #object[Transit$TaggedValue [TaggedValue: h, i there]]
I was tearing my hair out why transit wasn't properly consuming data from a JSON REST API.So you were parsing regular json as transit? I would stick to a dedicated json parser for that
@plexus: Exactly right. I wrongfully interpreted @dnolen's transit blog post to mean Transit could be used as a drop-in JSON parser. Now I use transit encoders with transit decoders, and use cheshire on the Clojure-side to parse non-transit JSON. Not sure if I've needed to parse non-transit JSON on client-sideā¦ any recommendations for that when that need inevitably arises?
@plexus: yeah. It's been a couple of years since this: āYou can JSON.parse and convert to ClojureScript data structures via cljs.core/js->clj but performance is even worse than cljs.reader/read-stringā (http://swannodette.github.io/2014/07/26/transit--clojurescript/) but I'll profile
Anyone aware of attempts to use Draft.js from CLJS?
@fasiha: Actually... you've only got two real options for parsing JSON to cljs AFAIK: (comp js->clj js/JSON.parse)
and (comp js->clj js/eval)
I made a little test and it gets you a tiny speedup (in Planck, so you might want to try another environment)
#!/usr/bin/env planck
(def test-data (-> (range 1000000) clj->js js/JSON.stringify))
(enable-console-print!)
(println (time (-> test-data js/JSON.parse js->clj hash)))
(println (time (-> test-data js/eval js->clj hash)))
2016-04-29 11:03:40.491 planck[40624:2161279] "Elapsed time: 2152.000000 msecs"
2016-04-29 11:03:40.492 planck[40624:2161279] -705118521
2016-04-29 11:03:42.633 planck[40624:2161279] "Elapsed time: 2141.000000 msecs"
2016-04-29 11:03:42.633 planck[40624:2161279] -705118521
@xcthulhu: well, I believe one can use Transit in this case, and it's 4x fasterāalso in Planck:
(println (time (-> test-data js/JSON.parse js->clj hash)))
; 2016-04-29 11:17:47.720 planck[13328:3830409] "Elapsed time: 1206.000000 msecs"
; 2016-04-29 11:17:47.720 planck[13328:3830409] -705118521
(println (time (-> test-data js/eval js->clj hash)))
; 2016-04-29 11:18:00.564 planck[13328:3830409] "Elapsed time: 1094.000000 msecs"
; 2016-04-29 11:18:00.565 planck[13328:3830409] -705118521
(require '[cognitect.transit :as t])
(def tra (partial t/read (t/reader :json)))
(println (time (-> test-data tra hash)))
; 2016-04-29 11:17:35.435 planck[13328:3830409] "Elapsed time: 247.000000 msecs"
; 2016-04-29 11:17:35.435 planck[13328:3830409] -705118521
And re-reading @dnolen's post, transit is billed as a solution to parsing straight, non-Transit JSON. It's just that ~
in strings messes everything up (and maybe other things)
It is kind-of an implementation detailā¦ but not sure how to have it be only an implementation detail, while letting users load it separately. So, for better or worse, it is there.
@mfikes: if I can bug you about it instead of asking Google, how come in iTerm2 and Terminal, Planck inserts 5D
whenever I type Control-Left arrow?
By the way @xcthulhu, no need to call (enable-console-print!)
. I noticed that it is accidentally causing things to delegate to some Ambly code that causes it to call NSLog
, which isnāt intended.
It's because in Terminal.app the 5D makes the terminal do a highlight of a matching paren, but it's not a console code that iTerm supports
@fasiha: The Line Editing keys in Planck are detailed here: http://planck-repl.org/repl.html
Ahh, @xcthulhu perhaps you are right. Perhaps @fasiha is seeing https://github.com/mfikes/planck/issues/119 (if so, update Planck)
@fasiha: was not suggesting you could in replace regular JSON parsing with Transit in the general case.
just that it might be worth exploring depending on the kind of data youāre sending over the wire - and that comment was mostly aimed at JavaScript users (many Clojure folks were already using EDN)
@dnolen: got it, I initially read too much into your ātransit-cljs addresses all of these issues at onceāāPEBKAC. I have seen the error of my ways š
It was working beautifully for days, then my app broke, and I spent the usual hours digging, and realized that some idiot started a sentence with ~
š
youād only get custom interpretation of JS objects and arrays and it would be slower
Well, above Transit chewed through JSON of a big numeric array 4x faster than js/JSON.parse.
for āequivalent" data payloads Iāve seen it barely beat JSON parse only under Chrome
Huh, how bizarre! Just a few minutes ago: https://clojurians.slack.com/archives/clojurescript/p1461943247001501 JSON.parse vs js/eval vs transit/read shootout in Planck. 1094 vs 1206 vs 247 ms.
@dnolen: I think I see. To get the same equivalent output as transit/read, I do need those js->clj
(and all three calls have hash
), but I do see that js/eval
& JSON.parse
are super-fast compared to everything else. And indeed hash
is painfully expensive š®
@fasiha: If you are going to always work with ClojureScript datastructures in ClojureScript, you're pretty much always better off with transit rather than JSON.parse
https://gist.github.com/bf02cc987c867520cabc4feb5c772d68
OW you should probably just stick with JSON.parse
, but you'll hit other performance walls later (in particular React isn't as fast when your data is mutable)
@xcthulhu: indeed, I have converted everything I can into transit. And I will use JSON.parse if I need to talk to any heathen services.
hey guys, can anyone give me tips on how to properly check for the existence of a js object from cljs?
I have a function that emits google analytics events when in production. If in dev it just logs them locally. In staging though the Google analytics object isn't present which is breaking my app
currently I have a (when js/ga (emit-event ...)
which is erroring on the when call to js/ga
@jonr: last time I did this I used (when (exists? js/SomeThing) ā¦)
I donāt know why it wouldnāt...
np, hope that works
@nberger: yeah, it looks like quite a bit was added, as far as closure compiler deps, in 1.8.51
https://gist.github.com/bostonaholic/776c246b2918293d13daacf399b50fca#gistcomment-1765284
@jonr Iāve found (some-> js/ga (emit-event ā¦))
useful if you need to thread the thing through some forms.
@jonr https://clojuredocs.org/clojure.core/some-%3E%3E > When expr is not nil, threads it into the first form (via ->>), and when that result is not nil, through the next etc
And in the meantime, thanks again @ddellacosta , that worked great
What is the best approach to say for a dev build load certain dev modules but a prod build omit dev modules and dev module calls? I know there is a closure-defines
option in the Closure Compiler but what about requiring?
@jupl: I tend to use different :source-paths for my cljsbuild dev/release configurations (assuming you are using leiningen)
https://github.com/binaryage/dirac/tree/master/src/dev/dirac
https://github.com/binaryage/dirac/tree/master/src/rel/dirac
look for src/dev
and src/rel
here: https://github.com/binaryage/dirac/blob/master/project.clj
we do the same thing