Demonstrating Web Worker: Sorting a 50K array in your browser
afshinm.github.io
afshinm.github.io
http://updates.html5rocks.com/2011/12/Transferable-Objects-L...
I wonder how much performance would improve if the example did use Transferable Objects.
Also note that the messages cannot encapsulate, say, closures or anything else that you can't JSON.stringify()/JSON.parse().
The real thing to consider is if the latency of the round trip messaging is less than just doing the work in place. With something like web workers you're going to have to hit the event loops when messaging back and forth which aren't always empty.
Slightly OT, but I found that you can detect the number of available cores with "navigator.hardwareConcurrency", but unfortunately that includes HT threads, at least in Chrome on OSX, so it says 8 instead of 4 on my machine. Is there a workaround?
Demonstrating Web Worker: Background
sorting a 50K array in your browser
Or something similar.The back-end was an embedded device that only accepted XML and could not do the calculation.
I had to have this do the allocation in IE8! So I wrote a timer based allocation routine that would release the UI thread enough to not lock up the browser. It worked (sort of), but was ugly and took way too long!
I'd expect sorting an array of 50k elements to be instantaneous on a modern machine, even in Javascript.
My first thought was, "WTF? Sorting 50k elements is a big deal?"
Windows 8
--------------------
Firefox v38 | 2629ms
Chrome v40 | 4281ms
IE v11 | 7899mshttps://news.ycombinator.com/item?id=2566365
Basically if web workers could access the GPU as well via WebGL.
Might want to mention that in the title.
So doing something that takes 8s doesn't have to block the UI at all. The "without webworkers" version should be renamed to "Naively programmed version" or something.
There aren't many operations in javascript which will block. The only real issue is that your javascript code executes in the same thread as UI. Which just means you need to think a bit harder about keeping it responsive.
"Start threads!" in programming is usually a lazy hack.
What's the benefit you get from programming like that?
Also, it's not faster, so what's the actual point?
The browser should use all CPU cores efficiently to make javascript fast. Exposing WebWorkers to javascript programmers IMHO is totally the wrong way to do that.
Edit: close. https://html.spec.whatwg.org/multipage/webappapis.html#timer...
"Timers can be nested; after five such nested timers, however, the interval is forced to be at least four milliseconds."