Increasing Performance with svgwrite

I’ve been working for quite some time on a Python project that generates a large-ish number of SVG files using Manfred Moitzi’s svgwrite package, which is pretty awesome.

However, I noticed that the runtime of this particular project was increasingly obnoxious, and only getting worse as the number of SVGs grew. So, out came cprofile, and sure enough, the bulk of the execution time was going through a tree of functions like check_svg_attribute_value, _check_svg_value and others seemingly related to validating the SVG during serialization.

The fix was pretty simple…

dwg = svgwrite.Drawing(size=(‘100px’,’100px’), debug=False)

Turns out that debug parameter is True by default, and setting it explicitly to False cut my execution time by almost 90%. Most of the remainder I’m sure is just I/O… (Mumbling as he ignores the rest of the profiler output.)