fontello / svgpath

SVG path low level transformations toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

very high cpu usage

humbleCoder1990 opened this issue · comments

I'm using "svgpath" heavily to draw svg in like this.

image

The problem is it uses very high cpu.
Without "svgpath" it usaully costs 10%.
But as soon as I use it, it goes to 40%.
Because I draw 20~30svgs.

Is there any solution? I guess it's very heavy math + a lot of string parsing..

If you have a lot ot data, parse can take some time, because speed is not infinite.

This comment is not really related to this lib, sorry, but why don't you use your Canvas2D context to perform the transform? With fill() that shouldn't be an issue (strokes would get scaled too though).
Or you could even do

const p1 = new Path2D();
p1.addPath(new Path2D("your long path"), { a: scale, d: scale, e: translateX * scale, f: translateY * scale }));
ctx.fill(p1);

And if you really do parse that many path-data every frame, you might consider storing the resulting Path2D objects.