-1

According to an article by a Mozilla engineer Web Workers take about ~40ms to startup (latency).

How fast are Web Workers? https://hacks.mozilla.org/2015/07/how-fast-are-web-workers/

Web workers take about 40 ms to be instantiated. Also, this time is pretty stable with variations of only a few milliseconds.

In a JSFiddle test I notice a varying startup latency between 15ms to 70ms. The latency does not appear to be stable around ~40ms. Chrome appears to be faster (6ms to 25ms).

var workerCode = URL.createObjectURL(blob); // no download latency
var worker = new Worker(workerCode);

https://jsfiddle.net/pvr5xroh/1/

Why do Web Workers have such a high startup latency?

optimalisatie
  • 341
  • 1
  • 11
  • That link is not documentation, it's an article about how Firefox OS used to work in 2015. – Álvaro González Jul 05 '17 at 08:19
  • I've referenced it as an article by a Mozilla engineer who explored the speed of Web Workers as an expert. The startup latency appears to apply in 2017 browsers. – optimalisatie Jul 05 '17 at 10:48
  • I understood otherwise from your question ("latency does not appear to be stable around ~40ms"). Whatever, I only meant that it's probably not an intentional delay imposed by the specs and, anyway, Firefox OS is no longer among us :_( – Álvaro González Jul 05 '17 at 11:01
  • You are correct in regards of the reference, however, the latency applies to all browsers/platforms, I simply searched for a corresponding article. The usage of Web Workers is currently severely restricted for frontend optimization due to this latency. – optimalisatie Jul 05 '17 at 11:15

1 Answers1

0

When you load a webworker like :

worker = new Worker('path/to/js');

The browser need to download 'path/to/js' before. Remember that JS is downloaded from the backend and executed in the frontend.

  • This answer does not apply to the question. The worker code in the test is loaded via URL.createObjectURL so that there is no download latency. https://jsfiddle.net/pvr5xroh/1/ I've modified the example code to make it more apparent. – optimalisatie Jul 05 '17 at 10:44
  • A webworker create a new thread, maybe it's just the duration that the browser take for create it... The latency can be variable if the browser or the CPU are busy. – Liara T'soni Jul 05 '17 at 13:51