Fork me on GitHub
#clojurescript
<
2017-04-24
>
mitchelkuijpers08:04:06

@dominicm Thanks but it still cannot require it somehow

deg12:04:37

I'm trying to deploy a small CLJS program on a "nano" AWS instance (lightsail, to be precise) with only 512MB RAM. lein cljsbuild once min fails, with out-of-memory. Is this expected? Anything I can tweak, or should I just pay a few bucks for a bigger instance?

souenzzo13:04:28

:optimizations :none may help. Clojurescript build's aren't cheap... In small cenarios, it may help https://anmonteiro.com/2017/02/compiling-clojurescript-projects-without-the-jvm/ But in a big project, JVM was more efficient(mem/cpu) than "nodevm"

timgilbert14:04:21

I've had some success tweaking -Xms and -Xmx settings on the JVM running lein. For circleci we're using JAVA_OPTS: "-Xms512m -Xmx2048m"

rarous14:04:48

Build it on CI server or somewhere else and deploy just the resulted JS to the nano instance.

dnolen13:04:29

@deg building ClojureScript often takes a lot of RAM - the typical thing is to have a build machine of some kind that just copies the compiled assets to S3 or whatever

deg13:04:30

Hmm, ok. Are there any good scripts or tools to help drive this process, or should I just roll my own? (My current flow was nice and simple, just a short script starting with a git pull. I was hoping to stay simple at first).

dnolen13:04:58

@deg you’ll need to roll your own but, aws s3 cp is pretty easy 🙂

dnolen13:04:33

@deg you can also copy those assets from your own machine if you want to keep it super simple of course

deg13:04:45

Yup, thanks. I'll do that. I was just trying to avoid the slippery slope of tool-writing. @dnolen

dnolen13:04:01

@deg to explain a bit more, advanced compilation is really memory intensive 1gb of RAM at a minimum usually if you don’t want it to to OOM or take forever

souenzzo13:04:36

My simple "reagent+re-frame" cljs compiles on a atom+2Gb with gitlab, docker and some other stuff.. 1Gb should be ok.

vikeri14:04:25

Any suggestions on http libs that works with environments that only has js/fetch instead of xhr (eg. node, React Native)?

qqq14:04:31

@souenzzo : how long does it take to compile? My cljs setup is so slow that I can't use my recent 15" MBP; and am ssh-ing into a server with 32GB of RAM to compile.

souenzzo14:04:55

About 2min. But its less then 1000 LOC.

qqq14:04:01

It's actually 8 cores + 32GB, but not sure if cljs is multi threaded.

tbaldridge14:04:37

@qqq how often are you doing a full recompile (with a clean), I've done tons of CLJS development on a MBP, and compilation is super snappy with simple optimizations and incremental compiliation

qqq14:04:19

@tbaldridge: I never do "clean"; I occasionally do "rm -rf" I'm building with :optimizations none and incremental compilation.

tbaldridge14:04:01

I also used figwheel so the JVM was always loaded, maybe that's the difference

tbaldridge14:04:33

as in, on my most recent project we had about 300 cljs files and my compilation times were about 700ms

mfikes14:04:27

@qqq By default, ClojureScript compilation is serial, but you can enable parallel compilation via a compiler flag: https://clojurescript.org/reference/compiler-options#parallel-build

qqq14:04:39

That's weird. I'm at 22 files, 1814 lines, and recompile is around 0.95 -> 0.99 seconds.

tbaldridge14:04:45

And that's "so slow I need to run it on a 8 core machine with 32GB"?

dnolen14:04:54

@qqq if your namespaces are pretty small parallel compilation may have little or no impact

qqq14:04:07

actually, it absolutely matters

qqq14:04:18

turning on parallel build, I went from 0.95 seconds to 2.06 seconds 🙂

dnolen14:04:27

oh ok nice, yeah it just depends

qqq14:04:42

yeah, going to disable parallel-build until files get larger

qqq14:04:21

I have no idea how compile time managed to increase 🙂

dnolen14:04:24

heh sorry I misread - but yeah I would expect that to happen

dnolen14:04:41

parallel build was implemented mostly for larger projects which were seeing >1 min build times

deas14:04:51

The new :npm-deps mechanism does not yet support modules which don't map to packages (like 'react-dom/server'), right?

anmonteiro15:04:12

@deas right. For that case you need to create a shim JS file exporting those

deas15:04:49

@anmonteiro Shiming by creating foreign libs using node-inputs, right? Does that mix with :npm-deps?

anmonteiro15:04:35

They should mix. If something doesn't work please report back

dominicm16:04:02

@mitchelkuijpers ^^ this might be of interest to you 🙂

john17:04:56

What would be the faster lookup mechanism in CLJS for a tight 8 way branch? A map lookup? Like (defn mk-lookup [v1 v2 v3 v4 v5 v6 v7 v8] {1 v1, 2 v2, 3 v3, 4 v4, 5 v5, 6 v6, 7 v7, 8 v8})? Or would a case statement be faster? Or something else?

dnolen17:04:44

@john you want case

john17:04:36

definitely at least twice as fast

dnolen17:04:34

if the case is simple we compile to JS switch

john17:04:16

Yeah, I think I'm winning the switch. It's just a super simple automata transition rule lookup, so it's a pretty tight loop.

dnolen17:04:09

right case becomes switch if the values are either all numbers, strings, or keywords (maybe also symbols, can’t remember)

john17:04:53

the test values, correct?

john17:04:28

Perhaps I'm not getting switch then. I'm passing in vectors of 3 numbers.

dnolen17:04:32

yeah no gains there

john17:04:05

Is there anyway to have case test for 3 values at a time, without a coll?

dnolen17:04:11

there are gains over using hashmap for dispatch of course

dnolen17:04:28

@john you need core.match if you want that

john17:04:44

I'll bring it in and try it out.

tankthinks18:04:28

Hey Everyone, I need to work with a foreign lib that returns native JS promises … what’s the most idiomatic way to deal with this

tankthinks18:04:08

right now my code looks some like:

(defn callback []
  (.then
    (.signinRedirectCallback (js/Oidc.UserManager.))
    (fn [user] (println "success! for " (-> user .-profile .-email)))))

grav18:04:21

@tankthinks I’d use threading, like

(-> (.signinRedirectCallback (js/Oidc.UserManager.))
    (.then (fn [user] (println "success! for " (-> user .-profile .-email)))))

tankthinks18:04:23

thanks @grav, that makes sense since promises always return promises i could add the (.catch ...) in the thread

grav18:04:32

Yes, exactly

mitchelkuijpers19:04:20

@dominicm thnx for the heads up! This will definitely work ^^

oahner20:04:34

I notice that *warn-on-infer* doesn't take user-defined externs (specified via :externs on opts) into account when using cljs.build.api/watch with *compiler* bound to an existing env; is that expected? If so, I take it I should be calling add-externs-sources myself when creating the env?

dnolen21:04:48

@oahner probably just an oversight, patch welcome

oahner21:04:27

@dnolen ahh, alright, altho I'm not sure where I'd fix it