
100,000 DOM Updates - llambda
http://swannodette.github.io/2013/08/02/100000-dom-updates/
======
swannodette
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/](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.

~~~
verroq
Works fine on Firefox 22

~~~
CountHackulus
Decently fast on Firefox 24a2.

------
ricardobeat
Where is the template and code that handles DOM manipulation, classes, etc?

How does it get so fast even without setImmediate? Does it use the postMessage
or MutationObserver tricks?

~~~
juandopazo
It looks that way, yes.
[http://i.imgur.com/ytgUlLu.jpg](http://i.imgur.com/ytgUlLu.jpg)

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

------
calibraxis
On swannodette's previous blogpost, he wrote in Reactive style:

    
    
        (defn ex0-key-events [prevent-default?]
          (->> (events js/window "keydown" prevent-default?)
               (map key-event->keycode)
               (filter KEYS)
               (map key->keyword)))
    

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

~~~
davidbalbert
My JavaScript isn't great, so I'm ignoring prevent-default?, but you can
probably do something like this:

    
    
      (defn events [object type]
        (let [out (chan)]
          (.addEventListener object type (fn [e] (put! out e)))
          out))

------
xanadohnt
Suggested not to view on a mobile device - works just fine on an iPhone 5,
actually.

~~~
nemetroid
It even runs along fine on my old ZTE Blade (the DOM updates are certainly not
in a hurry, but the text field remains responsive).

------
aa0
I started a lib for doing large tasks like this without blocking the paint
loop.

Everyone is welcome to contribute.

[https://github.com/iandrewfuchs/JSOperations](https://github.com/iandrewfuchs/JSOperations)

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

------
recursive
What language is that it's showing at the bottom?

~~~
joeblau
Clojure[1]. I watched two one-hour videos trying to learn the language and my
brain exploded.

[http://en.wikipedia.org/wiki/Clojure](http://en.wikipedia.org/wiki/Clojure)

~~~
kristopolous
That sounds horribly painful. I hope you are doing ok.

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

------
gvickers
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)

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

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

~~~
cpeterso
Can you use window.postMessage() on Firefox? Barnes & Noble's (?!) NobleJS
library has a setImmediate() polyfill, which uses postMessage() on Firefox:

[https://github.com/NobleJS/setImmediate/blob/master/setImmed...](https://github.com/NobleJS/setImmediate/blob/master/setImmediate.js#L202)

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

------
lastinline
Nightly - 25.0a1 Firefox - 22 Chrome - 28.0.1500.95

way way way faster on chrome than on either nightly/firefox

~~~
bzbarsky
Yep, because it's running different code in different browsers. See
swannodette's comments above.

------
voltagex_
I wonder if the fact it's immensely slow on FF 22 vs Chrome 28 is worth a
Bugzilla ticket

~~~
BrendanEich
The bug for MessageChannel is
[https://bugzilla.mozilla.org/show_bug.cgi?id=677638](https://bugzilla.mozilla.org/show_bug.cgi?id=677638)
(I just poked it, we should fix it).

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](https://news.ycombinator.com/item?id=6154170).

------
jokoon
What's the point of using clojure to js ?

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

------
ghh
Isn't this 100x100 = 10,000 updates?

~~~
swannodette
Oops you are correct, brain stuck on other benchmarks I've been working on -
the posts now actually involve 100,000 updates and/or processes. Thanks

