I have an SVG drawing with 10138 parts, so it runs slowly.
I want to make it run more like http://workshop.chromeexperiments.com/globe
Here are the solutions/questions I'm considering
I just want to make it faster .. thoughts?
Here is a screenshot
SVG gives better performance with smaller number of objects or larger surface. Canvas gives better performance with smaller surface or larger number of objects. SVG is vector based and composed of shapes. Canvas is raster based and composed of pixel.
Canvas gives better performance with smaller surface or larger number of objects. SVG can be modified through script and CSS. Canvas can be modified through script only. Multiple graphical elements, which become the part of the page's DOM tree.
The long answer: Those SVG DOM references mean that some of the footwork of dealing with the things you draw is done for you. And SVG is faster when rendering really large objects, but slower when rendering many objects.
As a simplified rule of thumb:
So I 10138 objects to be kept in memory with SVG will slow down things (though I can't say what the hard limits are). If you get into this range of objects I believe that canvas and WebGL might provide better performances. Most modern browser already support hardware accelerated canvas rendering.
However doing user interaction is more involved with Canvas compared to SVG.
You can also try to mix them (see here for more details).
Here are some useful resources:
The slowdown for an SVG with a very large number of pieces comes from the non-retained mode of SVG. Without more details about what your SVG looks like and how it behaves, it's hard to make concrete suggestions. So in general:
If your graphic is generally static (you don't need to track mouse events per graphical object) you can use an HTML5 canvas instead (where the drawing commands blit pixels to an image and thereafter you basically have a static image).
If your graphic has a lot of repeated parts, using SVG with <use>
elements may reduce the memory footprint and improve performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With