Parallel Wasm with Web Workers
The process of building a complex application that performs heavy computation or other resource-intensive work can benefit greatly from using threads. Threads allow you to perform operations in parallel by dividing functionality among tasks that run independently. At of writing this, support for threads in WebAssembly is in the Feature Proposal phase. In this phase, the specification hasn't been written and the feature isn't implemented. Fortunately, JavaScript provides threading capabilities in the form of Web Workers. In this section, we'll demonstrate how to use JavaScript's Web Workers API to interact with Wasm modules in separate threads.
Web Workers and WebAssembly
Web Workers allow you to utilize threads in the browser, which can improve the performance of your application by offloading some of the logic from the main (UI) thread. Worker threads are also capable of performing I/O using XMLHttpRequest
. Worker threads communicate with the main thread by...