memononen / nanosvg

Simple stupid SVG parser
zlib License
1.71k stars 363 forks source link

nanosvg is too slow but easy to make it faster #80

Closed tpecholt closed 7 years ago

tpecholt commented 7 years ago

I am reading 8MB svg and it takes 30 seconds to parse. When profiling with VerySleepy I found it's because of svg__addShape adds new shape to the tail of the list. Tail is not cached so this operation is very slow. When I changed it to add it to the list's head (no iteration) parsing time went down to 1s! The speedup is too big to ignore so I think the code should be changed. If you still want to have list of shapes in correct order you can reverse the list at the end of parsing.

lieff commented 7 years ago

Can you share svg sample?

tpecholt commented 7 years ago

Just a debug plot of part of a road with normals plot.zip

memononen commented 7 years ago

Good find. I think the list should be ordered. Would you be willing to make a PR for the fix?

tpecholt commented 7 years ago

PR has been made