Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JS and Parallel Processing(!?)

JS and Parallel Processing(!?)

For a long time, JavaScript was missing any kind of processing threads. While the single-threaded model added to developer comfort, it also made the platform unable to do serious and time-consuming calculations, and the only way to circumvent it was to do it on a remote server.

Luckily, with the introduction and widespread adoption of Web Workers, we can now do resource-intensive calculations on background threads. A Web Worker allows you to run JavaScript in the background, without affecting the performance of the page. Even if you are running really resource intense code in the browser, you can continue to do whatever you want: clicking, selecting things, etc., while the Web Worker runs in the background.

In this talk, we will explore:

Web Workers, how and when you can use them, and their peculiarities.
Polyfilling for naughty browsers
Future: WebGL, Canvas2D, and other marvels browser vendors are cooking up.

Joe Karlsson

April 27, 2019
Tweet

More Decks by Joe Karlsson

Other Decks in Technology

Transcript

  1. @JoeKarlsson1 ! 5 Can Do Anything Multithreads Can do Easy

    to Program Easy to Port Code *For non-data intensive operations *Faster Than Multithreads Easy to Debug/Test Why Single Threads?
  2. @JoeKarlsson1 ! 10 • Parsing large JSON set • Image

    Processing • Sound Processing • Real Time Analytics Things that take a lot of time
  3. @JoeKarlsson1 ! 19 • Faster • More Responsive • Battery

    efficient • Support in every major browser (IE 10+)
  4. @JoeKarlsson1 ! 27 Web Workers operate in a different context

    They cannot directly access the Window or DOM
  5. @JoeKarlsson1 ! 51 • Web Workers are relatively heavy- weight,

    and are not intended to be used in large numbers • Web Workers are amazing but hard to manage
  6. @JoeKarlsson1 ! 55 Additional Resources 1. Code: https://github.com/JoeKarlsson/live-code/tree/master/web-workers 2. Slides:

    3. Web Workers: https://developer.mozilla.org/en-US/docs/Web/API/ Web_Workers_API/Functions_and_classes_available_to_workers
 4. Web Workers: http://techslides.com/html5-web-workers-for-ajax-requests
 5. Workers: https://html.spec.whatwg.org/multipage/workers.html#shared- workers-introduction