W3C home > Mailing lists > Public > site-comments@w3.org > June 2012

Workers demo is slow

From: Alex G <latinsud@gmail.com>
Date: Sun, 24 Jun 2012 20:24:12 +0000
Message-Id: <CAFj1KnsiLO4j-UjTE2QiHkrEMS3cQH0XEKFHiCn+w9Tw_pCbOQ@mail.gmail.com>
To: site-comments@w3.org
Hi, i think you should consider modifying the workers demo as it is
slow in some browsers.

I filed a bug report some time ago:
http://code.google.com/p/chromium/issues/detail?id=85686

They came out that the problem is too much communication between the
worker and the main page. This ends up slowing main page too in the
end.

- An initial solution would be to report primes only one prime number each 1000.

- A better solution would imply taking time into account (eg: limit to
10 messages/second). This is my implementation of it:

function run() {
 var n = 1;
 var lastTime = 0;

 search: while (running) {
   n += 1;
   for (var i = 2; i <= Math.sqrt(n); i += 1)
     if (n % i == 0)
      continue search;

   // found a prime!
   var d = Date.now();
   if ( d - lastTime > 100 ) {
    lastTime = d;
    postMessage(n);
   }
 }
}
Received on Sunday, 24 June 2012 21:15:09 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 24 October 2012 16:21:34 GMT