-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Hi, I'm coming from a discussion in image-rs/image-png#114. My issue is regarding the very slow reading of png images in wasm. @HeroicKatora identified that the issue might come from inflate calls. So I've tried to set up a very simple example to verify performance drops.
For this I'm using the file at https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-all-titles-in-ns0.gz. I decoded then re-encoded it with libflate, otherwise the original encoding was not decodable by inflate. It is a 296Mb file when decoded, 88Mb encoded. In the example code, there is a main.rs in which I roughly measure native decoding performances. And in the lib.rs file, there are wasm exposed functions, enabling me to copy-paste different versions of the inflating and trying them in the browser.
So I've tried each version available from inflate in native, and 3 versions in wasm. Here are the results.
version | native speed | wasm speed |
---|---|---|
inflate_bytes | 2.8s | 20.6s |
InflateStream | 2.8s | not tested |
InflateWriter | 2.9s | not tested |
DeflateDecoder | 0.64s | 4.6s |
DeflateDecoderBuf | 3.0s | not tested |
--------- | -------------- | ------------ |
libflate | 2.2s | 4.8s |
As we can see, inflate is one order of magnitude slower in wasm than in native. Libflate however is "only" 2x slower in a wasm context. In addition, we can see here that using DeflateDecoder
is a lot faster than using InflateStream
, which is the one used in the png crate (there are probably reasons for this that I'm not aware of).
I'm not familiar enough with DEFLATE to try to understand what might be the reason for this slow down in the code but I wanted to report the issue. I hope you might have an idea of what is wrong, and probably a fix to enjoy inflate in wasm ^^.