[whatwg] WebWorkers and images

On Thu, Jan 13, 2011 at 5:08 AM, Berend-Jan Wever <skylined at chromium.org> wrote:
> I ended up creating a PageWorker object, which is constructed in the page
> rather then in a WebWorker. It uses setInterval to repeatedly run a function
> in the background to do the image processing directly on the canvas imageD
> data. To reduce overhead, each interval runs the function in a small loop
> for a certain number of ms. After each interval, the browser gets some time
> to do UI updating. This seems to work well in my Mandelbrot fractal
> renderer; the browser remains responsive:
> http://skypher.com/SkyLined/demo/FractalZoomer/Mandel.html

That's exactly the cumbersome, problematic programming model that web
workers specifically seek to eliminate.

(I loaded that, and the browser became painfully unresponsive in FF
3.6; opening a menu took about a quarter second.  In order to keep the
browser properly responsive, you'd need to return so often that the
10ms minimum timer duration in most browsers will cause the algorithm
to take notably longer.)

Note that if your computational work is entirely working with
ImageData, you can send the ImageData to a thread.  It's limiting (you
can't blit images to the canvas that way, since you don't have the
Canvas interface), but it may be enough for your case.

-- 
Glenn Maynard

Received on Thursday, 13 January 2011 02:35:38 UTC