samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.73k stars 69 forks source link

Performance issue with loadImage when processing SVGs #192

Open Vandomas opened 4 days ago

Vandomas commented 4 days ago

I am using skia-canvas to generate images on the backend of my server.

My workflow is as follows:

  1. I generate an SVG.
  2. I optimize it using svgo.
  3. I load the optimized SVG into skia-canvas using the loadImage function, passing a DATA URI.

The process of loading the image (loadImage) takes anywhere from 70ms to 200ms. This is significantly slower than the rest of my workflow, which typically completes in less than 5ms. In most cases, loadImage takes over 150ms, which is a bottleneck for my application.

Caching the images is not an option since each image is unique and dynamically generated.

I would like to know:

Are there any ways to speed up the loadImage process? Would converting the SVG to PNG before loading be faster? If so, are there libraries or approaches you can recommend for efficiently converting SVG to raster images in this context?

Any guidance or suggestions for improving the performance of this step would be greatly appreciated. Thank you!