Monday, April 18, 2011

0.9 - Sundae - Gets buff - threadpool

For anyone who doesn't know Sundae, is a canvas reference tester library built in Javascript. My goal is get Processing.js, c3dl, and XB-pointstream to use this tool.

Skip the blog:

The bulk
After my initial 0.8 release where I dabbled into the world of web workers, Sundae still had massive performance hogs.

What did I do about it? I went on IRC and spoke to the community! David Humphrey provided some interesting insights on my issue. My problem was that although I was now using web workers my code was STILL synchronous. The solution became, remodel the workers to grab work items from a queue.

So including edge cases, my workflow became:
  • queue.push called, is there a available worker?
    • Yes -> use it
    • No -> add to queue
  • worker.onmessage, are there more items to work on?
    • Yes -> do it
    • No -> make worker available
I so happy when not only did this code work, the runtime when down to 1s from 5s on my calibration tests on a Quad core machine! Although on my much slower aging laptop the performance gain was less dramatic still halving the runtime.

Get the threadpool code here
and use it like this:


But from the pastebin you'll need to change onnmessage

onmessage = function(data){
...Does something meaningful with your returned data...

Help me out!

No comments:

Post a Comment