Fork me on GitHub
#cljsrn
<
2018-04-16
>
mfikes15:04:03

If you are using re-natal by default there should be no need to have the ClojureScript compiler index the (gigantic) node_modules directory (because the React Native packager takes care of pulling code out of there as needed). By setting the ClojureScript compiler option :npm-deps false my (start-figwheel "ios") is nearly instantaneous (whereas previously it would spend a significant chunk of time indexing node_modules). If you want to try this to see if it also works for you, you will need to patch Figwheel so that it allows false as a valid value for :npm-deps.

đź’Ą 4
pesterhazy16:04:11

Is npm-deps on by default in recent versions of the cljs compiler?

pesterhazy16:04:08

It seems to me that indexing node_modules is not a good default behavior, given that JS based tools don't do any indexing as far as I know (they just open the directory you require)

mfikes17:04:39

@pesterhazy Yes. I don’t know if this is a recent change, but it is definitely the case now. See case 4 in https://dev.clojure.org/jira/browse/CLJS-2494

mfikes17:04:51

This has to do with the compiler indexing things in node_modules, presumably so that the compiler can itself directly make use of code in there. So, the right thing to do appears to be to turn it off, unless you are doing something that actually makes use of that feature.

mfikes17:04:40

For my project, disabling it seems to have no ill effects, and I’m getting back, say 20 to 40 seconds (I haven’t actually measured it)

jeaye17:04:11

Oh, neat. I bet I could save some time on it too, then.

jeaye17:04:00

I'd love to use :npm-deps for managing things, rather than package.json. It just hasn't proved reliable yet.

mfikes17:04:51

An interesting case, I suppose, is when you actually want to use :npm-deps to consume some library and have it go through Closure (per https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules), but if you aren’t doing that, then all of the other stuff in node_modules is really there for the packager to dredge through, right?

jeaye18:04:37

Having all the used deps go through Closure is a good thing, isn't it? I'd think, in the near future, we should all be doing it.

jeaye18:04:58

Aside from managing the deps in your project.clj (or whatever) and having easy require access to the packages, that's the next biggest sell. More optimization.

mfikes18:04:04

If we can get everything to go through Closure, yes, that would definitely be great. I suspect that is essentially the “don’t embrace the packager” approach.

mfikes19:04:57

I timed it on my system (an older 2012 Mac Pro), and disabling :npm-deps saves me 45 seconds when doing (start-figwheel "ios")

jeaye19:04:04

@mfikes You might consider noting that in the PR as well.

mfikes19:04:54

Oh, the PR for Figwheel is one that needs to happen anyway. But, I do think we need a re-natal PR to ultimately change the default project.clj that gets set up to include this config.

jeaye19:04:07

Good thinking.

mfikes19:04:15

I’ll add a note in the Figwheel PR though, just to prod Bruce along 🙂

jeaye19:04:49

Excellent.

dotemacs23:04:20

Thanks for doing this @mfikes. Just tried it on the project I’m working on for android and it took ~25 seconds without and with your patch. But maybe I’m running it wrong: I’ve started the emulator and Metro bundler and then I fired up the REPL via CIDER while in the project dir. Once it came up, I ran (start-figwheel "android"). Originally I had lein-figwheel “0.5.14” installed. My project’s node_modules directory has 687 modules installed:

$ ls -1 node_modules/ | wc -l

mfikes23:04:01

@dotemacs Are you running ClojureScript 1.10.238?

mfikes23:04:59

(The :npm-deps false is a 1.10.238 new feature.)

dotemacs23:04:46

ah, good point… my bad… Installed 1.10.238 and that took it down a few seconds!

dotemacs23:04:10

Around 20 second mark instead of 25 seconds

mfikes23:04:55

@dotemacs After having tried that, it would be interesting to see if a second startup is much faster now. For me (start-figwheel "ios") drops from around 45 seconds to being instant (maybe 1 or 2 seconds).