Closed djahandarie closed 4 weeks ago
Have you tried .pixels
? This doesn't need to be encoded as a PNG.
https://github.com/yisibl/resvg-js/blob/39eaa225b3d9b9274d4e27fe4f01922bd601c06a/__test__/wasm.spec.ts#L65
Also, enabling SIMD will result in faster speeds. https://github.com/yisibl/resvg-js/pull/148
Thank you for the super fast response! :smile:
I wasn't aware of that! It is basically what I was thinking of for my bullet 1.
I tried it out, and indeed it cut out all the useless png encoding/decoding.
const resvgJS = new Resvg(new Uint8Array(m.content), opts);
const pixels = resvgJS.render().pixels;
drawPromises.push(createImageBitmap(new ImageData(new Uint8ClampedArray(pixels), m.width, m.height)).then((bitmap) => {
return {canvases: m.canvases, image: bitmap};
}));
(There might be some better way than using ImageData
> ImageBitmap
here but I couldn't figure it out lol... this part of web APIs is so confusing. Maybe something with VideoFrame
would be a more direct way of using the array? No clue)
Anyways, this gave us a nice performance boost.
The SIMD stuff also looks super nice!! I'm not sure we want to take on the burden of compiling this in our build since we aren't a rust project, but if push comes to shove with performance we might do it...
Thank you so much.
Can you just use putImageData
? Here is an example: https://github.com/yisibl/resvg-js/pull/304
Where does yomitan
use resvg-js
? I didn't find the code.
Yes, it took a tiny bit of refactoring but putImageData
worked! Thanks.
I hadn't committed it yet -- just did now. You can see it here: https://github.com/yomidevs/yomitan/tree/performance-canvas in the latest commit. (The code is a huge mess right now unfortunately, will get it cleaned up soon so we can merge it to master)
Hi! I'm using resvg-js in wasm in the browser (in a Chrome extension, yomitan).
I use it basically like this:
(Note: we
Promise.all
the decode promises in order to have a very tightdrawImage
loop)Basically, we need to render a large number of SVGs in a limited amount of time budget, which we currently cannot meet, and we are observing the following:
asPng
, and 40% inrender
for resvg, suggesting a potential 2x speedupI could see any of the following resvg-js changes potentially helping:
drawImage
We would prefer it in order of 3, 2, 1. But ease of implementation is probably in order of 1, 2, 3. And 3 is probably a bit too niche (but don't let me stop you if you think it seems good as it's our ideal...).
What do you folks think? Do any of these options seem appropriate / feasible to include in the library?