I've been playing around with the performance of Processing.js/canvas
vs Raphael/SVG/div. Here are some frames per second (fps) results I'm
currently seeing from the 5 leading browsers:
http://svbreakaway.info/tp.php#jan12
The plots are maybe a bit overwhelming, but
- Rows are canvas size. Columns are browser.
- fps is on the y-axis. # balls on the x-axis.
- The red line (generally max fps) is without any rendering.
- The green line is rendering using Processing.js. The green area is
the difference - to try to make it easier to see.. well, the
difference.
- The solid blue line is a simple replacement of ellipse() and line()
in the Processing.js code with calls to Raphael circle() and path() -
creating a new object for each ball and line on each frame.
- The dashed blue line is where I allocate the Raphael circle and path
objects at the setup and then reuse them for the whole run (using
calls to attr() on the objects to change their position from frame to
frame). Again, the blue area is the difference between non-rendering
(the red line) and the Raphael/SVG results (solid and dashed blue
lines).
I think the results were fairly predictable - Chrome did well,
Processing.js did well, the version of the Raphael/SVG testcase that
reused the objects (generally) did better than the create-a-new-object-
each-time version.
There were a couple surprises - Opera and IE9 exhibit what I *think*
are problems (but it could be something I'm doing), and my new-and-
improved-through-reuse version of the Raphael/SVG testcase was
actually worse in some of the Safari runs (at a small number of
objects, 10 balls).
The current version of the benchmark is here:
http://svbreakaway.info/dfe/
in case you want to try it yourself. (I'll try to sort out the IE9
problem yet)
Regarding the original post, one (maybe obvious) option is the
judicious call to loop() and noLoop(). I'm using Processing.js for my
report-drawing code in the benchmark runner (dfe) using loop() when
woken up by the Dromaeo Javascript code and noLoop() at the bottom of
draw(). Just thought I'd mention it.
Sorry for the long post,
Mike