<story><title>The Path to Parallel JavaScript</title><url>https://blog.mozilla.org/javascript/2015/02/26/the-path-to-parallel-javascript/</url></story><parent_chain></parent_chain><comment><author>reissbaker</author><text>This is nice for some pretty limited use cases, but the most common use case for multithreading in app-like programs (which is what Worker-based apps presumably service: these are not documents) is removing latency from the UI thread. But as long as only the main thread can touch the UI, and the main thread also can&amp;#x27;t access shared memory, this limits uses of this to scenarios where copying the entire render state from a Worker is reasonably fast — in which case, Workers currently already solve the problem. This proposed implementation of shared memory doesn&amp;#x27;t actually solve one of the big remaining needs for shared memory, which is when it&amp;#x27;s prohibitively expensive to copy state between a Worker thread and the UI thread at 60fps.&lt;p&gt;For example, Workers aren&amp;#x27;t particularly useful for games in their current iteration: the overhead of copying the state of the world back to the rendering thread is high. This is exactly the problem that shared memory &lt;i&gt;would&lt;/i&gt; solve, were it not limited to Workers. This puts web export (or even primary web-based game authorship) at a significant disadvantage as compared to native apps: native code can share memory, and web-based implementations can&amp;#x27;t. In many cases architectures that are optimal for shared-memory threading are pathological when the rendering thread requires copies, meaning that threading gets thrown out the window for web. Even with asm.js-compiled &amp;quot;near-native&amp;quot; performance on the single core, you can only use 25% of the available CPU if you can&amp;#x27;t use multithreading. A 4x performance hit is the difference between 60fps and 15fps... Or 15fps and ~4fps.&lt;p&gt;The title of the blog post got me pretty excited, but the proposal is fairly disappointing in terms of unlocking better performance for web apps. The use cases here are pretty limited to things like CPU-bound number crunching, and I doubt too many people are running machine learning algorithms in a browser as compared to the number people who&amp;#x27;re using browsers to, y&amp;#x27;know, render UIs. By all means scope the problem down to sharing primitive data in ArrayBuffers — we can build abstractions on top of that! — but limiting it to Worker threads makes it near-useless for most web applications. Workers already solve the use cases for UIs that can tolerate copies between the UI thread and the Worker threads, and this proposal doesn&amp;#x27;t allow us to solve needs for UIs that can&amp;#x27;t.</text></comment>
<story><title>The Path to Parallel JavaScript</title><url>https://blog.mozilla.org/javascript/2015/02/26/the-path-to-parallel-javascript/</url></story><parent_chain></parent_chain><comment><author>amelius</author><text>Great developments, since, imho, we really need multi-threading to make decent user-interfaces (ones without hick-ups due to blocking of the cpu-resource).&lt;p&gt;I think what we need is immutable data-structures to be shareable between threads. This approach should also allow structural sharing between threads, allowing for efficient and safe data structures.&lt;p&gt;Also, I could see a use for a mechanism where a thread creates a data-structure, then marks it as read-only, such that it can become shared.</text></comment>