Technically there is nothing holding you back from using :advanced on node, IF 
you supply all externs that is. And this is where the problem lies, you cannot 
easily provide externs since the closure compiler doesn't understand "require" 
properly.

CloSure assumes there is one global namespace that it controls fully and can 
rearrange as it likes. It is called whole program optimization after all. In 
node however each module has it's own little world it lives in and the use of 
global is discouraged. Most node modules usually are not part of the 
optimization either. The current strategy of require/UMD/ES6 module support in 
closure involves rewriting them to look like closure modules, this still has 
the requirement that it requires all code. Someone would still need to write 
externs for all modules that ship with node though.


However, you can cut down the size of :simple by a bit if you also use the 
flags you have for your :advanced build. 

(cljs.build.api/build "src" 
  {:main 'hello-world.core 
   :output-to "simple.js" 
   :optimizations :simple 
   :optimize-constants true 
   :static-fns true
   :pretty-print false
   :target :nodejs})

static-fns and optimize-constants are implicit for :advanced btw, you only need 
to specify them for :simple.

Depending of what your hello-world.core looks like :advanced may have 
eliminated almost everything. Which means you are comparing Apples and Oranges 
since most real world programs wont eliminate this much.



TL;DR: No, it is unlikely :advanced will be officially supported. If you 
compare programs that do actual work the difference will be much smaller and 
startup time usually becomes much less of an issue (if you can even call it an 
issue really).

HTH,
/thomas


On Monday, January 25, 2016 at 6:11:44 AM UTC+1, Roc King wrote:
> Hi all!
> 
> It seems unclear from the quick start wiki page[1]. But in Clojurescript 
> Unraveled[2], it says that :optimizations :none is *mandatory* for nodejs.
> 
> Can we relay on advanced optimizations when targeting nodejs(currently or in 
> the future)?
> 
> Thanks in advance.
> 
> 
> Some reasons(other than runtime performance) to use advanced optimizations:
> 
> . fast startup time and small memory footprint
> . easy to deployment
> . hard to reverse engineering
> 
> without them, clojurescript + nodejs are not so attractive than clojure + jvm.
> 
> 
> The hello world program from the quick start wiki page will take half a 
> second without optimizations:
> 
> $ env time -f '%E %M' node none.js >/dev/null
> 0:00.50 232320
> 
> It is 4x slower and uses 4x memory than the empty nodejs program:
> 
> $ env time -f '%E %M' node </dev/null
> 0:00.13 59264
> 
> and is worse than clojure-jvm plus some tweaks for options:
> 
> $ env time -f '%E %M' java -jamvm -XX:+TieredCompilation 
> -Xbootclasspath/a:$HOME/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar
>  clojure.main - <<< '(println "hello clojure-jvm")' >/dev/null
> 0:00.50 175024
> 
> And how could we deploy those things?
> 
> $ du -shc none.js out
> 4.0K  main.js
> 2.7M  out
> 2.8M  total
> $ find none.js out -type f | wc -l
> 26
> 
> Without dead code removal, it will be even worse for non-trival programs.
> 
> 
> :optimizations :simple will solve the deployment problem and will reduce 
> startup time and memory footprint. But it is still 2x slower and uses 3x 
> memory than the empty nodejs program:
> 
> $ env time -f '%E %M' node simple.js >/dev/null
> 0:00.30 174912
> $ du -sh simple.js 
> 708K  simple.js
> 
> And there are some bugs(timeout in core.async, in particular) under simple 
> optimizations. Again, there is no dead code removal in simple optimizations. 
> The Library Problem[3] still exists in clojurescript + nodejs.
> 
> 
> Under advanced optimizations, it will use 1.2x time and memory:
> 
> $ env time -f '%E %M' node advanced.js >/dev/null
> 0:00.16 73552
> $ du -sh advanced.js
> 84K   advanced.js
> 
> With the help of dead code removal, we paid for what we actually use.
> 
> 
> The hello world program and the build options are the same as in the wiki 
> page[1]:
> 
> (ns hello-world.core
>   (:require [cljs.nodejs :as nodejs]))
> (nodejs/enable-util-print!)
> (defn -main [& args]
>   (println "Hello world!"))
> (set! *main-cli-fn* -main)
> 
> (cljs.build.api/build "src"
>   {:main 'hello-world.core
>    :output-to "none.js"
>    :target :nodejs})
> 
> simple.js and advanced.js are built using the following options:
> 
> (cljs.build.api/build "src"
>   {:main 'hello-world.core
>    :output-to "simple.js"
>    :optimizations :simple
>    :target :nodejs})
> 
> (cljs.build.api/build "src"
>   {:main 'hello-world.core
>    :output-to "advanced.js"
>    :optimizations :advanced
>    :optimize-constants true
>    :static-fns true
>    :target :nodejs})
> 
> version of nodejs and java are 0.12 and 1.7 respectively:
> 
> $ node -v
> v0.12.9
> 
> $ java -version
> java version "1.7.0_55"
> OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1~0.12.04.2)
> OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
> 
> 
> [1]: 
> https://github.com/clojure/clojurescript/wiki/Quick-Start/7f2360af24953303b282771870085620a83f0711#user-content-running-clojurescript-on-nodejs
> 
> [2]: 
> https://web.archive.org/web/20150716040442/http://funcool.github.io/clojurescript-unraveled#none
> 
> [3]: 
> https://github.com/clojure/clojurescript/wiki/Rationale#user-content-the-library-problem

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.

Reply via email to