Cross Browser Canvas Support & Speed
It used to be that if you wanted to draw—curves, shapes, and polyhedra—with Javascript, you would have been out of luck. However, almost all modern browsers now supportcanvas, which is a nifty technology that finally lets Javascript out of its DOMy prison.
For the most part it works well. To see it in action, take a look at the always-excellent John Resig’s Processing.js, Ilmari Heikkinen’s CAKE, and my own Algorithm Ink (which I’ll write more about soon).
Standards Compliance
In the grand tradition of browser technologies, Canvas isn’t fully supported by everyone, yet.
Firefox 3 and Opera 9.5 both get good marks. Ironically, it’s Apple—who originated the technology—that hasn’t gotten around to implementing some of the basics. In particular, Safari isn’t yet standards compliant and doesn’t implement the fundamental setTransform and transform. Transform is, however, supported in the the nightly build of Webkit.
IE is the only browser that doesn’t support Canvas at all (although, with Google’s excanvas you can pretend that it does).
To see exactly how well your favorite browser does, head over to the test report generator. Do note some of the tests are fairly pedantic and don’t have much real-world meaning. To see how your browser stacks up against other browsers, go here. The same caveat still applies here as well, so take them with a grain of a salt.
Speed Tests
In general, Safari is always the fastest, followed closely by Firefox (in most cases), with Opera lagging in far third. Excanvas-enabled IE wasn’t really aware that the race had started. In general, it looks like what slows Firefox down is stroked arcs, while for Opera it’s filled arcs.
You can find the code for the tests here. I averaged the render times over 10,000 draws
Excanvas-enabled IE uses VML under the hood, so every object you draw remains as a live, unrasterized object that eats memory and potentially CPU time. This means that I wasn’t able to test IE in the same way I tested the other browsers: making 10,000 smiley faces causes IE to collapse into an unresponsive mess and die (IE can’t handle all the happiness?).
You can also see how the time increases as more and more objects are added in IE: Drawing 100 circles took only 1.1ms per circle, drawing 10000 circles took 2.14ms per circle, and drawing 50000 took a whopping 21.77ms per circle.
RT @azaaza Cross Browser Canvas Support & Speed | Follow @azaaza on Twitter | All blog posts
Michael
Canvas is, in my opinion, the most exciting feature to hit the web, ever. I’m really surprised it’s still somewhat obscure among developers, but that might be the IE factor.
I’m using Canvas to make a small physics based game. You don’t get great performance yet, but I really feel Canvas could replace Flash for simple web games some day.
Maciej Stachowiak
Safari certainly does implement transform() (but not setTransform yet). I think just about anything you can do with setTransform() can be done with transform() possibly combined with saving and restoring the context.
Blair McBride
Now all we need is some standardized text rendering API – I think Firefox 3 is the only one to have this so far.
Exec
Nice, really looking forward to more hardware accelerated canvas in “true” 3D :D
@Michael
Have you seen these canvas games and apps yet?
Processed tower defense ( http://ptdef.com/ )
Four games from Nihilogic ( http://www.nihilogic.dk/labs/javascript-games/ )
ImageFX ( http://www.nihilogic.dk/labs/imagefx/ )
Processing.js ( http://ejohn.org/blog/processingjs/ )
website design
Give it some time. It’s new. Besides, Opera is so much better than FF or Safari in so many ways. That’s just my opinion, of course.
Aza Raskin
@Maciej: Thanks for catching that. I’ve updated the blog post accordingly (*looks sheepish*).
@Exec: I’m looking forward to hardware accelerated 2D, more than 3D ;)
Thomas Hurst
Huh, I don’t see that here. Reported speed is similar between Firefox 3 and Opera 9.50; Firefox was actually a bit slower at some of the tests.
Additionally, Firefox likes popping up warnings that the JS “may have stopped responding”, and indeed it’s generally unusable while the benchmark’s running; even opening a new empty tab takes many seconds. On the other hand, my 104-tab (ahem) Opera session remains responsive.
Eran Galperin
CANVAS is formally supported in the working draft for HTML 5. Hopefully in a few years it will be a standard and cross-browser implemented (basically means getting IE to support it…)
ohxten
“Give it some time. It’s new. Besides, Opera is so much better than FF or Safari in so many ways. That’s just my opinion, of course.”
Hey! I made that exact comment on reddit…
Gen Kanai
Nice work Aza!
One of the more fun Canvas applications I’ve come across recently is Philip Lenssen’s “Bomomo”:
http://bomomo.com/
Aza Raskin
@Thomas: Interesting. I wonder why we see this discrepancy? I have been testing on a MacBook Air, with OS X 10.5. How about you?
elliottcable
I’m surprised that nobody’s brought up SVG yet! SVG is so much awesome-r than canvas tags, I can’t begin to express it.
Y’all should play with it some time, it’s at least mostly supported in all modern browsers.
funtomas
How about support for c3DL in Firefox? Is it slated?
Philip Taylor
Blair: A standardised text rendering API was added to the specification recently – http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas.html#text
(Firefox 3 has a non-standard Mozilla-specific API, which was done before this part of the spec was written.)
Nobody has implemented this yet, but hopefully it will be in the next one or two rounds of browser releases.
Michael
@Exec: Some of those are new to me, thanks for the links.
an0n1 m0us
I just want to know one thing. If we use Google’s excanvas for IE, can we finally do the equivalent of rounded corners (border-radius) across Fx3 and IE6/7/8 **now**? As in today?
Thomas Hurst
Aza: This is on a Windows XP system with a dual core Opteron. I think OS X is lacking PGO optimized builds, which probably accounts for at least part of it.
Also, perhaps their drawing optimizations weren’t as effective on OS X: http://my.opera.com/desktopteam/blog/2008/03/28/painting-performance-fixes
Aza Raskin
@Thomas: Thanks for the feedback. I had no idea there would be so much variation across operating systems.
@Maciej: It appears that Safari 3.0.4 indeed doesn’t support transform. The nightly, however, does.
Mark Rowe
@Aza: I believe .transform was added to WebKit prior to the most recent release of Safari, Safari 3.1.
Rob
In tests that I’ve run, Firefox 3 and Opera 9.5 split the number two and three spots rather evenly, while Safari 3.1 for Windows was typically 2-3x faster.
Opera 9.5 and Firefox 3 both took about 280 µs to draw a filled circle, Safari 3.1 took 115 µs. While this difference may seem huge, it really isn’t. There’s nothing I’ve ever toyed around with that was completely do-able in Safari but would have been too slow in Opera or Firefox.
Philip
Hi, Aza. Very interesting.
Unfortunately I had trouble seeing the graphs because they were in Flash. JPG or PNG images make life easeir for weaker processors and users who avoid proprietary software. And if you have to use Flash, version 7 works better for those users.
Thanks and keep up the excellent work!
Aza
@Rob: Thanks for the extra data points. I agree with you that these speed results are a bit pedantic. Interesting, though.
@Phillip: I feel a little ashamed that I used Flash for my graphs. I really should have used Canvas ;)
Rick
Excanvas works for IE8 beta?
fxaueq
gkcihqgwcfrwokksvdlirktcnqzmzk
what zit tooya (tm)
i agree opera is way better than firefox. firefox doesnt memmorize your tabs after u close the browser but opera does. firefox sux
creadiff
Thank you very much for testing all this feature, I am currently working on cross-browser animations so this is very useful to me !
Mitur Binesderti
It seems odd that you don’t bother to mention Google’s Chrome. There’s no date on this article but you’re talking about Opera 9.5 and it’s up to 10.6 now so maybe this was written way before it even existed.
Zayıflama Lida Fx15 Ve Biber Hapı Zlfvbh
Safari certainly does implement transform() (but not setTransform yet). I think just about anything you can do with setTransform() can be done with transform() possibly combined with saving and restoring the context.