Very impressive, I am glad I started studying clojure earlier this summer, I feel it will be a powerful tool in years to come. Currently working on a Cljs life simulation engine (flora, fauna, think Rich Hickeys Ant Colony demo)
I feel like a broken record for saying this but ... most production JS is shipped minified just like the code for this post. The entire code base is 25K gzipped smaller than ES6 generators + jQuery + Underscore + Immutable Collection Library + Promises implementation which is what ClojureScript + core.async delivers!
Even more fun and guaranteed to crash everything except for desktop Chrome & WebKit Nightly is the follow up http://swannodette.github.io/2013/08/02/100000-processes/ - here we create 100,000 go blocks (akin to 100,000 goroutines in golang) and run them all at the same time.
I tried on firefox 22, it took 4:54 mn to complete , each color was around 4 to 8 numbers.
I then tried on IE10 to have some fun : I took 7 sec to complete, each color was between 1 and 3 lines ...
Just to explain core.async uses the fastest dispatching mechanism available, Firefox doesn't provide anything sensible like MessageChannel so we just resort to setTimeout. setTimeout in all major browsers has a 5ms delay between nested calls - thus all the discussion about setImmediate the past 2 years or so.
I am surprised about IE 10 since we do use setImmediate if available, but I haven't done much testing there - will need to look into it.
FF takes longer just because the script is pretty broken, imo: it only processes 4-5 chars per 16ms frame, and reflowing/painting each frame tick here is the expensive thing in all browsers. As a result, the behavior of the script in wall-clock time is O(N^2/K) where N is the number of chars and K is the number it processes in a single tick. Furthermore, its CPU consumption is pretty much constant no matter what K is for a wide range of K.
We could use postMessage but it's rather frustrating since that's a global post and we have detect our own messages on the other side. So until Firefox supports MessageChannel we're unlikely to go that route.
What I see is that the page is using self-throttling to a ridiculous extent in Firefox, but not Chrome, with way too few letters changed between paints. Are you doing a single letter from each async callback or something?
Luckily joeblau uploaded his consciousness into his Roomba nanoseconds before his brain exploded, that's how he can still post to HN. So at least there's that.
It's always great to see ClojureScript pushing forward on things like this. I've recently started focusing on Clojure and Clojure script for personal projects and I'm really enjoying functional programming.
The test needs to be changed to try postMessage on Firefox and any other browser version lacking MessageChannel, or else it should just fail with an alert -- "waiting for Firefox to implement MessageChannel" -- because what it's doing on Firefox is an irrelevant timekiller, as bz showed a few comments above at https://news.ycombinator.com/item?id=6154170.
Where did the `events` function (line 2) come from? Does it create a lazy dechunked seq which takes events from a buffered channel? Is it built atop RxJS?
(Sorry, I haven't yet used ClojureScript, only Clojure. Googling didn't help.)
The argument for Clojurescript is about the same as for Clojure on the JVM. To get a (subjectively) more expressive language but have it run on an already popular platform and take advantage from that.
This really should say right up front that you should not compare it across browsers because it's serving significantly different code to the different browsers.
62 comments
[ 2.8 ms ] story [ 128 ms ] threadI am surprised about IE 10 since we do use setImmediate if available, but I haven't done much testing there - will need to look into it.
https://github.com/NobleJS/setImmediate/blob/master/setImmed...
What I see is that the page is using self-throttling to a ridiculous extent in Firefox, but not Chrome, with way too few letters changed between paints. Are you doing a single letter from each async callback or something?
http://en.wikipedia.org/wiki/Clojure
Everyone is welcome to contribute.
https://github.com/iandrewfuchs/JSOperations
How does it get so fast even without setImmediate? Does it use the postMessage or MutationObserver tricks?
[0] https://bugzilla.mozilla.org/show_bug.cgi?id=874174
The test needs to be changed to try postMessage on Firefox and any other browser version lacking MessageChannel, or else it should just fail with an alert -- "waiting for Firefox to implement MessageChannel" -- because what it's doing on Firefox is an irrelevant timekiller, as bz showed a few comments above at https://news.ycombinator.com/item?id=6154170.
(Sorry, I haven't yet used ClojureScript, only Clojure. Googling didn't help.)
way way way faster on chrome than on either nightly/firefox