title: Why do my webworkers perform so unexpectedly bad?
body: <p>In order to familiarize myself with web workers I have written a small test where 2 arrays are added element wise. The positions in the target array are distributed to 4 workers. I wanted to measure the performance and experienced a rude awakening.</p>
  
  <pre><code>///init///
  const workers = new Array(4), global_elements = 250000;
  
  function createArray(value, elements) {
      return new Int8Array(elements).fill(value);
  }
  
  let a = createArray(1, global_elements), b = createArray(2,global_elements), c = createArray(0,global_elements), data_recived = 0;
  
  window.URL = window.URL || window.webkitURL;
  
  for(let i=0; i&lt;4; ++i) {
      let response = `self.onmessage=function(e){
                          for(let i=${i*global_elements}; i&lt;${i*global_elements+global_elements}; ++i) {
                                  e.data[2][i] = e.data[0][i] + e.data[1][i];
                          }
                          postMessage(0);
                      }`;
      workers[i] = new Worker(URL.createObjectURL(new Blob([response], {type: 'application/javascript'})));
      workers[i].onmessage = function(e) {
          if(++data_recived === 4) {
              t1 = performance.now();
              console.log(t1-t0);
          }
      };
  }
  ///end-init///    
  
  //normal
  let t0 = performance.now();
  for(let i=0; i&lt;global_elements; ++i) {
      c[i] = a[i] + b[i];
  }
  let t1 = performance.now();
  console.log(t1-t0);
  
  //worker
  t0 = performance.now();
  for(let i=0; i&lt;4; ++i) {
      workers[i].postMessage([a,b,c]);
  }
  </code></pre>
  
  <p>Sadly, here workers can not even score with increasing global_elements number.</p>
  
  <p>elements:  normal | workers</p>
  
  <p>2500:    0.1  |  51.4<br>
  25000:   1.5  |  66.5<br>
  250000:  4.1  |  182<br></p>
  
  <p>(I know the performance tests are not optimal.)</p>
  
  <p>Why do my webworkers perform so unexpectedly bad?</p>