Improved performance of new version of ReaderSvg library

by abenedik 1. June 2010 15:33

The biggest improvement of the new version of ReaderSvg is improved performance.

To prepare the new version a lot of time was spent in a profiler. I used some very complex files from some common applications that can save drawings into svg file.

It was quickly clear that the most of the CPU cycles were spend to solve svg's style inheritance. A lot of the time was also used to resolve many possibilities to define styles in svg file (svg styles, css, attributes, ect.).

For example if we have a complex hierarchy, the root group element can define stroke thickness for the path element that is 10 children away. The process of getting the correct style declarations was before not optimal and is now much faster.

The SVG Specification allows some very complex stlye declararions that are very rarely used. The code that tries to support all the possibilities is much quite complex and takes significant time to execute. I have analyzed the svg files I have (really a lot of them - lots of them from users feedback) and found out that almost all of them are using only simple style declarations. So I have decided that by default only simple style declarations would be processed. But if needed the complex style processing can be used by setting the new OptimizeStyleProcessing property on ReaderSvg to false.

For example the following style declaration is by default not processed correctly (but magically it is read correctly with setting OptimizeStyleProcessing to false):

<defs>
   <style type="text/css"><![CDATA[
            .mummy circle, .mummy rect, .mummy polygon { fill: green}
            .mummy > .thischild { fill: red }
            .primus + .secundus { fill: red }
            .mummy circle:first-child { fill: red}
         ]]></style>
</defs>

 

Improved performance is not the only improvement. There is more:

  • Added support for text and tspan baseline-shift.
  • Now polyline and polygon are read as WPF's Polyline and Polygon elements (in previous version they were read as Path).
  • Fixed measuring size - improved for bigger stroke thickness on some shapes (when AutoSize property on ReaderSvg is true - by default).
  • Fixed SvgViewbox and SvgDrawing controls - they do not throw exceptions when Source is not set but some other property like AutoSize is set.


As usual the existing customers can download the new version from their User Account page. Others can download a 60-days trial version from my Downloads page.

Tags: , , ,

ReaderSvg