> There is something VERY strange going on in Firefox v14 -- the SVG test is MUCH faster than in Chrome and Safari and the Canvastest is absurdly slow and the line isn't actually rendered!
>
> Must be doing something wrong -- but teh program is very simple -- I don't think I saw this problem last year ???
) which on several browsers ends up showing one or very few line segments. The default -- which would produce output like the SVG test, incidentally -- is
. Interesting is that Safari, Chrome, Safari, Opera and IE9 exhibit some
First there's Opera.
Run your Canvas test in latest Opera and it is... the epitome of 'sluggish'; in fact, it is more than
400 TIMES SLOWER than the SVG render -- which is
blazingly fast compared to other browsers, but that's another item:
Opera 12: Canvas => 5000 pcs @ 17848 msecs, where last 250 pcs @ 878 msecs
Opera 12: SVG => 5000 @ 26, last 250 @ 1
(*
nobody* beats Opera's numbers for SVG, BTW, except there's that
one browser manufacturer and Redmond resident...)
Chrome 20: Canvas => 5000 @ 31, last 250 @ 2
Chrome 20, SVG => 5000 @ 2303, last 250 @ 226
Note the 100x speed difference with SVG/Opera! Visually, you can see Chrome updating, Opera is just 'bang!' and done, so it's not a measurement error.
The last250 times are relevant here as they do not include any possible differences in the implementation of the 'animation timers' in the various browsers. Opera keeps near constant time O(1) in SVG while the other browsers all exhibit O(n^2) behaviour for SVG. Again, the Redmond native excluded, here, but you'll see that happening when it arrives further below.
Firefox 14, Canvas => 5000 @ 602, last 250 @ 31
Firefox 14, SVG => 5000 @ 90732, last 250 @ 10191
This looks just plain horrible for SVG. (It also nicely explains why I had such headaches getting a site to perform with FF a while back.)
Keep in mind that these numbers for Canvas are for the original '
destination-atop' gist
http://bl.ocks.org/1297383 ; when you change that to '
source-over', as we will at the end, the time difference factor jumps by about another
decade and some things change dramatically. Firefox SVG isn't O(n) but probably
O(n^2) as
Firefox 14, SVG => 500 @ 97, last 250 @ 5
is not a factor of 10 compared to the 5000 pcs render, but rather a factor of 100 --> O(n^2) SVG performance. Ouch.
In case anyone believes 'the best' FF engineers were bought off by Google/Chrome, think again, because here's Chrome for comparison:
Chrome 20, SVG => 500 @ 36, last 250 @ 24
so Chrome is also somewhere close to O(n^2), given their 5000 pcs number of 2303. Yes, they're probably somewhere between O(n log n) and O(n^2) performance -- golly! -- but it still is _way_ different from Opera 12: 500 @ 4, last 250 @ 2 while 5000 @ 26, meaning we're looking at something between O(n) and O(1) instead for Opera; (O(n) would imply a factor of 10 in time between the 500 and the 5000 sample, while actual measurement produces 26 instead of expected O(n) = 40). Now the boys and gals at Opera sure show smarts, here.
Anyway, if anybody has been buying off anyone else's engineers, it's got to be Opera. ;-) Or maybe those Redmontanians, who knows... pecunia non olet, eh.
Alas, so much for the Google/Chrome vs. FF conspiracy theory. *Busted*
Okay, Safari/Win, another Webkitty like Chrome, sort of, but...
Safari 5/Win, Canvas => 5000 @ 95, last 250 @ 4
Safari 5/Win, SVG => 5000 @ 1568, last 250 @ 151
while SVG => 500 @ 32, last250 @ 12
so something of an O(n log n) here? O(n^2) would get us 3200 instead of 1568. There's a factor of 2 in there: it's either overhead being optimized on the fly or something that's leaning towards O(n log n) underneath.
Recall that Chrome did take 2303 msecs for the same and a 5000/500 ratio of 2303/36, so there's that same O(n^2) estimate vs reality factor 2 (3600:2302) again. Indeed looks like another Webkitty here.
For now, given that 2x factor, my bet is on O(n^2) for both, with some optimizations elsewhere which show up when you scale the buggers.
Incidentally, Safari is the one where the original Canvas '
destination-atop' gist rendered just like the SVG one; given
https://developer.mozilla.org/samples/canvas-tutorial/6_1_canvas_composite.html we can conclude that Safari is offering incomplete support in the canvas composition mode department. Stay tuned for some surprises with the others...
Meanwhile, there's IE9, in both 32-bit and 64-bit renditions:
IE9/32-bit, Canvas => 5000 @ 1011, last 250 @ 51
IE9/32, SVG => 5000 @ 20, last 250 @ 1
Whoa, Nelly! SVG => 500 @ 2, last 250 @ 1
beats up-to-now-fastest kid on the block Opera and leaves all the other browser lovers eating Microsoft dust. Watch my tail lights, baby! See the red-shift, hon'?
An O(n) animal in SVG, which is very nice work!
IE9/64, Canvas => 5000 @ 964, last 250 @ 47
IE9/64, SVG => 5000 @ 96, last 250 @ 4
Both IE9/32 and IE9/64 exhibit O(n) behaviour (IE9/64, Canvas => 500 @ 98, last 250 @ 47) for canvas for 'destination-atop', while they exhibit something between O(1) and O(n) for SVG (IE9/64, SVG => 500 @ 33, last 250 @ 4)
Keep in mind that 'n' for canvas is pixels, not line segments (nodes) like it would be for SVG.
Also keep in mind that this is
canvas in destination-atop composition mode.
Oh, and incidentally,
bl.ocks.org code b0rks like the best of them in IE9: the iframe gets rendered (praise Allah) but nothing about the accompanying source code display nor any of the markdown-ed text for ye skunners.
Conclusion?
The O(...) expression in observed behaviour is bloody important when you're going to scale this up, i.e. intend to use SVG or Canvas with large numbers of graphic elements (here, only lines have been tested, but it gives some surprising results already)
The browsers which are
expected to scale nicely in SVG are the ones which have algorithms underneath which exhibit O(n) cost or better, so that would be
Opera and IE9.
Anything that's O(n^2) or close to that will have your old CS math professors frothing at the mouth.
The slow buggers at scale are: Chrome, Firefox, Safari, as each is certainly performing worse than O(n log n) and only Safari and Chrome are marginally better than raw unadulterated O(n^2).
Hold it! What about <Canvas>?
Right. Canvas. It's ... faster.
Iff... ... ...
Theoretically it should _
always_ be able to beat SVG at any scale because there's no node hierarchy to maintain/search and it's the same pixels it's got to push, but apparently some folks have a spot of trouble coping with certain composition modes, Opera in particular.
Have a look at this bugger:
http://bl.ocks.org/3331545and notice the differences:
Firefox 14, Canvas =>
3250 @ 312 , last 250 @ 1, for: source-over
3500 @ 340 , last 250 @ 28, for: destination-atop
Chrome 20, Canvas =>
3250 @ 19 , last 250 @ 1, for: source-over
3500 @ 20 , last 250 @ 1, for: destination-atop
Safari 5/Win, Canvas =>
3250 @ 29 , last 250 @ 2, for: source-over
3500 @ 32 , last 250 @ 3, for: destination-atop
Opera 12, Canvas =>
3250 @ 6969 , last 250 @ 8, for: source-over
3500 @ 9818, , last 250 @ 2849, for: destination-atop
IE9/32, Canvas =>
3250 @ 453, last 250 @ 2, for: source-over
3500 @ 505, last 250 @ 52, for: destination-atop
IE9/64, Canvas =>
3250 @ 417, last 250 @ 3, for: source-over
3500 @ 465, last 250 @ 48, for: destination-atop
The numbers to watch here are the 'last 250' ones: these (and a few other numbers) tell us that
Canvas is indeed matching the theoretical expectation of 'faster than SVG, always', only when you stick with the 'source-over' composition mode in any browser.
The surprising bit is the slowdown factor for the various browsers, which are thought provoking, particularly in the case of Opera, where they disappear right off into that elusive WTF County:
- Webkitties shrug about composition modes (but Safari and Chrome agree to disagree on the final render result nevertheless): they don't really care. composition mode isn't a speed factor to consider there, maybe it's 2x if you really want to push home a point about it, but that's already stretching it.
- FireFox, OTOH, hits the brakes as soon as you dare tread outside the 'source-over' composition realm: depending on where you look you observe at least an order of magnitude slowdown: 10..30, with the higher number when there's more opaque pixels to juggle. Not nice.
- IE9 lands in the same ballpark at about 20x slowdown for anything but 'source-over'.
- The big surprise is Opera, which hits us with a ~ 300x (yes, that's two significant zeroes right there, y'all! Hot dang!) slowdown, BUT this only happens if you dare use destination-atop, destination-in, copy, source-in or source-out composition modes. Apparently, someone over at Opera had it in for these, since any other mode is on par with the default 'source-over' mode.
Canvas, only in a rerunTo close this off, here are the SVG vs. Canvas numbers again, where canvas now has been done in 'source-over' mode to mimic the SVG behaviour. The corrected canvas benchmark can be found here:
http://bl.ocks.org/3331937
Opera 12: Canvas => 5000 @ 103 , last 250 @ 8 (compare to 5000 @ 17848 previously!)
Opera 12: SVG => 5000 @ 26, last 250 @ 1
Chrome 20: Canvas => 5000 @ 25 , last 250 @ 3 (previously 5000 @ 31)
Chrome 20, SVG => 5000 @ 2303, last 250 @ 226
Firefox 14, Canvas => 5000 @ 35 , last 250 @ 2 (previously 5000 @ 602)
Firefox 14, SVG => 5000 @ 90732, last 250 @ 10191
Safari 5/Win, Canvas => 5000 @ 48 , last 250 @ 3 (previously 5000 @ 95 [*])
Safari 5/Win, SVG => 5000 @ 1568, last 250 @ 151
IE9/32-bit, Canvas => 5000 @ 50, last 250 @ 2 (previously 5000 @ 1011)
IE9/32, SVG => 5000 @ 20, last 250 @1
IE9/64, Canvas => 5000 @ 47, last 250 @ 3 (previously 5000 @ 964)
IE9/64, SVG => 5000 @ 96, last 250 @ 4
[*] when you run these tests yourself, you'll note that running them again can produce significant differences for the smaller numbers, up to a factor of 2: another run for Safari produced 84 instead of 48 msecs for 5000 line segments. Of course the differences for the bigger numbers are
very much less, it's just the small ones which have this big a 'jitter' to them, obviously.
This is why performance measurement sites such as
jsperf.com run tests multiple times and calculate avg and spread of the measured times to decide whether it's a good run or not, and what the reported number should be. I've been lazy in that I only ran the tests 2 or 3 times. The factors and O(...) expressions shown here remained near constant enough throughout for my tastes: Opera in 'destination-atop' mode didn't get any faster by running it again and again and again, for one.
And what about Stephen Bannasch's numbers?
Well, I can't explain the FF numbers Stephen's got, apart from the observed slowness, but FF over here still is faster at canvas in 'destination-atop' than when doing SVG. Maybe FF was of a different mind last year, when it was at a different build number, but it might be prudent to check the numbers here: my numbers originate from one box, so unless I fubarred the bunch, yours should at least match these by a close-to-constant factor when you rerun the tests on another machine, using the same browser versions.
I went and rechecked mine, but noticing your own blind spot hasn't ever been my forte, so the German adage applies, as ever: Vertrauen ist gut, Kontrolle ist besser. (And when you google that, the translation you'll dig up is off: Kontrolle isn't so much Control as it is Verification, i.e. 'Making sure/checking up on something'. English control is rather more like german Führung (yeah yeah, I know... glad you saw it too), so a good translation would keep the spirit of it, keep Frank Zappa in mind, hence end up as 'Trust is good, Scrutiny is better'. Your Central Scrutinizer would certainly agree, so why wouldn't you?)
The Final Verdict
If you want FAST at scale, you go for SVG on IE9 and Opera -- though canvas is close behind or on par -- while the other, better known 'non-M$ browsers' all suffer from a severe case of O(n^2) when running in SVG, where Firefox beats them all (Safari and Chrome) when it comes to 'animation'. It's just a wee bit of an exaggeration to state that for large graphs you don't need d3 transitions for animations but just let Firefox run and enjoy the drawing while it happens @ 90 seconds for 5000 line segments, which is ~ 45 times slower than the runner-up in the 'snails pace' competition: Chrome.
Pity the display doesn't update while JavaScript is running, as now Firefox makes SVG rendering look like Bill the Cat barfing a hairball.
That '45' right there might give you ideas, but when you look closer at the numbers you'll agree that both suffer from O(n^2) type behaviour, which makes that little '45' utterly insignificant when you scale up the complexity of your SVG renderings. For these buggers, the only way out for you as a user and graphics coder is using Canvas, which exhibits O(1) or O(n) behaviour for all browsers,
but for an entirely different n:
the number of pixels you're juggling, and with a noticeable different constant at that.
With Firefox, your fastest race will be run in Canvas, with the default '
source-over' composition mode. Luck has it the others are all pretty darn fast there, too.
Is there such a thing as a booby prize?
Met vriendelijke groeten / Best regards,
Ger Hobbelt
--------------------------------------------------
web:
http://www.hobbelt.com/ http://www.hebbut.net/
mail:
g...@hobbelt.commobile: +31-6-11 120 978
--------------------------------------------------