[ClojureScript] Re: Will advanced optimizations be officially supported on nodejs?

2016-01-28 Thread Roc King
About the bug(or issue) I mentioned before on cljs.core.async/timeout.


Several days ago, I have tried core.async and then got sucked... Google gave me 
two links:
. "cljsbuild :simple optimization breaks cljs.core.async timeout on Node.js" [1]
. "ASYNC-110 0.1.346, using >! crashes with no method 'setTimeout', when 
targeting node" [2]
none of them could solve my problem(at that time)...

So I worried about the support on nodejs:
. there are much fewer people use clojurescript on nodejs than on browsers, 
isn't it?
. Is the bug still exist after one year?
. Is there someone use it seriously?
and then came here for some help.

After got more familiar with clojurescript, I realized that ASYNC-110 fully 
described(and gave several working solutions!)[3] this issue.
But if "goog.global" was used before "goog.global = global"(the solution used 
in clojurescript[4]), the same problem will occur.
This is the exactly situation I have encountered several days ago: I wrote '(go 
(https://groups.google.com/forum/#!topic/clojurescript/5yrg7T2wSz8
[2]: http://dev.clojure.org/jira/browse/ASYNC-110
[3]: http://dev.clojure.org/jira/browse/ASYNC-110#comment-37658
[4]: http://dev.clojure.org/jira/browse/ASYNC-110#comment-37793

-- 
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.


[ClojureScript] Re: Will advanced optimizations be officially supported on nodejs?

2016-01-28 Thread Roc King
Thomas, Thank for you reply.

The hello-world.core is from "Quick start" wiki page of clojurescript on 
github. With explicit :static-fns :optimize-constants and :optimizations 
:simple, there is no significant difference.
Yes, the comparison was did on hello world program and is unfair indeed, 
because I didn't have a real program to compare yet...
The point is, dead code removal is nice for both browser and nodejs, right? It 
encourages modular(instead of monolithic) libraries. Whether it is worth to 
support is another question.

To me, the startup time and memory usage are very important.
I prefer to use clojure-jvm when I need writing something down. But clojure-jvm 
is not suitable for utility programs(in unix style) obviously. So I need some 
alternatives in this area...
If clojurescript+nodejs could not startup significant faster than clojure-jvm, 
why would I leave clojure-jvm in the first place?
I'm not saying that clojurescript should support :advanced(or be suitable for 
utility programs). I just want to know that whether :advanced is one of the 
goals of clojurescript on nodejs.
And I'm pretty happy with the current status: it is unlikely to got official 
support, but many people(projects) use it without problems.

-- 
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.


Re: [ClojureScript] Re: Will advanced optimizations be officially supported on nodejs?

2016-01-28 Thread Roc King
在 2016年1月25日星期一 UTC+8下午6:15:44,Moe Aboulkheir写道:
> On Mon, Jan 25, 2016 at 10:04 AM, Thomas Heller  wrote:
> 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.
> 
> 
> It's not a fantastic or delicate solution, but depending on this project: 
> https://github.com/nervous-systems/cljs-nodejs-externs will pull in externs 
> for Node's built-in modules.
> 
> 
> Take care,
> Moe 

Got it. No need to provide externs manually any more. Thanks :)

-- 
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.


Re: [ClojureScript] Re: Will advanced optimizations be officially supported on nodejs?

2016-01-25 Thread Moe Aboulkheir
On Mon, Jan 25, 2016 at 10:04 AM, Thomas Heller  wrote:

> 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.


It's not a fantastic or delicate solution, but depending on this project:
https://github.com/nervous-systems/cljs-nodejs-externs will pull in externs
for Node's built-in modules.

Take care,
Moe

-- 
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.


[ClojureScript] Re: Will advanced optimizations be officially supported on nodejs?

2016-01-25 Thread Thomas Heller
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  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~