Recently we were engaged by a company in the UK and some designers based out of Paris, to bring a 3D model designed in Google SketchUp to life online. This would hardly be noteworthy had we been allowed to use Flash to deliver an interactive experience. But for this project, we were specifically tasked to use HTML5 friendly techniques. Thank you Mr. Jobs. Unfortunately, we can’t share any links at this time but we promise we will share once we launch. So what happens when you try to draw 8000+ lines on a canvas?
The model, aka the “constellation” pictured above, had over 8000 lines and over 300 spheres. The designer, thankfully, had used a monochromatic palette. This was a good thing because it meant that we would not have to worry about z-sorting the lines and circles. Our mission was to render this puppy, fly around and cull what we couldn’t see.
Once we had parsed the data (that’s a future post and a half), we were ecstatic, it was nearly imperceptibly different from what we were seeing in SketchUp… but.. then we glanced at our frame rate stats and we were only getting 9fps. As we moved our camera in and out we saw the fps hover between 4-9fps. We thought, ok, maybe Safari on mac is not as fast as Chrome. Alas! Chrome was performing slighly worse, with a lower bottom end at 3-6fps.
Where was our sweet spot? How many lines and spheres can one draw on the canvas and achieve acceptable frame rates? What is more taxing, lines or spheres? We would be happy with 20fps. We broke out the lab coats and went to work creating versions of the constellation with decreasing amounts of lines and spheres. We also separated the lines from the spheres and ran some tests independently. Keep in mind, that this is not uniform test since, as you can see in the screenshot above, the lines are not spread evenly in x,y or z space nor are the total number of lines and circles drawn on screen at any given time. So this is also a test of pure javascript performance, looping through the arrays and deciding if a line should be drawn.
The Tests
We ran 3 tests. For our 1st test, we took every third, then fourth line etc. from the original 8847 lines in the array. The second and third test gave us insight into how much overhead the circles were adding to the drawing methods.
We wanted to share our findings with respect to the performance (measured in fps) we recorded in FireFox, Chrome and Safari on the Mac and their counterparts on the PC. All tests were conducted at 1200×800. We were also very interested in seeing how the HTML5 canvas performed on the iPad because part of the end project is to produce similar results in the browser on the iPhone and iPad. All of these browsers support the canvas and some browsers have even fashioned marketing campaigns around their performance. But what we found surprising was the chasm separating the slowest from the fastest frame rates.
As you will see in the tables below, Firefox was pathetically slow at rendering the model on both mac and pc. Safari was better than Chrome for some reason, as it is widely believed Chrome owns the distinction of being the fastest browser.
In Test 2 and 3, you can see that drawing the circles was not an insignificant overhead, representing a 2-5 frame jump at the lower end of the range.
| Test 1: All, Every 3rd, 4th, 5th , 6th and 7th line element | |||||
| Chrome (mac) | Safari (mac) | Safari 5.0.3 (pc) | Chrome 5.0.375 (pc) | Firefox 3.6.2 (pc) | |
|---|---|---|---|---|---|
| 8847 lines | 2-5fps | 4-7fps | 4-9fps | 3-6fps | 2-3fps |
| 2949 lines | 8-14fps | 9-19fps | 10-15fps | 7-12fps | 2-13fps |
| 2212 lines | 9-16fps | 12-23fps | 11-17fps | 10-17fps | 6-16fps |
| 1770 lines | 12-19fps | 14-24fps | 13-20fps | 11-20fps | 1-19fps |
| 1475 lines | 12-21fps | 15-25fps | 14-19fps | 12-21fps | 9-21fps |
| 1264 lines | 15-23fps | 16-26fps | 15-20fps | 12-16fps | 9-21fps |
| Test 2: Lines and Circles | |||||
| iPad (gen1) | Safari (mac) | Safari 5.0.3 (pc) | Chrome 5.0.375 (pc) | Firefox 3.6.2 (pc) | |
| 1000 Lines 263 Circles | 3-9fps | 25-49fps | 17-24fps | 12-18fps | 13-18fps |
| 800 Lines 263 Circles | 3-10fps | 28-50fps | 18-21fps | 14-29fps | 11-24fps |
| 600 Lines 263 Circles | 4-12fps | 34-57fps | 17-23fps | 15-22fps | 18-29fps |
| 400 Lines 263 Circles | 6-13fps | 34-58fps | 18-24fps | 16-22fps | 18-29fps |
| 200 Lines 263 Circles | 5-13fps | 49-91fps | 22-25fps | 11-22fps | 27-35fps |
| Test 3: No Circles | |||||
| iPad (gen1) | Safari (mac) | Safari 5.0.3 (pc) | Chrome 5.0.375 (pc) | Firefox 3.6.2 (pc) | |
| 1000 Lines 0 Circles | 4-11fps | 29-48fps | 21-37fps | 18-30fps | 18-33fps |
| 800 Lines 0 Circles | 4-12fps | 34-52fps | 27-39fps | 20-32fps | 22-34fps |
| 600 Lines 0 Circles | 4-13fps | 38-71fps | 28-41fps | 24-43fps | 22-42fps |
| 400 Lines 0 Circles | 7-14fps | 54-89fps | 36-42fps | 28-36fps | 34-43fps |
| 200 Lines 0 Circles | 10-27fps | 82-135fps | 27-52fps | 42-64fps | 38-57fps |
While we acknowledge this isn’t completely a fair test, it shows you that Chrome is not necessarily king, and that there is serious room for improvement from Firefox. We look forward to updating this post with some numbers run against FF4 and Chrome 9. Perhaps the best news was that Safari performed well for us, and is considered the target browser for the project. We will update this post in the coming weeks with greater detail about this project as this data has more to tell us about the performance of canvas drawing methods across the browsers.








facebook
facebook
twitter
rss
rss





