-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Big slow-down in WebAssembly (wasm) #55
Comments
I believe the main reason is that DeflateDecoder was added to the API much more recently than InflateStream. InflateStream (and DeflateDecoderBuf which uses it) have a 32k buffer, DeflateDecoder doesn't so maybe there is some difference there. Not sure what libflate has by default. If you curious about speed, you may also want to compare flate2 with the rust back-end enabled. |
I've opened a pull request for the benchmark harness for According to the investigation in image-rs/image-png#114, 85% of time is spent in @mpizenberg for this to be actually tackled I suggest providing a step-by-step guide to reproducing the setup that exhibits the slowdown. If I were a library maintainer and never dealt with wasm before, I wouldn't bother unless it was very clear what to do. |
@Shnatsel ok, I'll update the example repo with exact instructions to reproduce behavior in coming days. |
I have updated the associated repository (https://github.com/mpizenberg/wasm-inflate) with instructions in the readme to reproduce this benchmark. Versions have changed since last April. On my computer, with rustc 1.36.0, inflate 0.4.5, libflate 0.1.25, wasm-bindgen 0.2.47, I have the following results with native rust compilation:
And in wasm with Firefox 67.0.4 I got:
Two things are already noticeably different from last time in April.
Unfortunately I don't think I'll have time to investigate this further for quite some time, but at least its better documented now. |
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.
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 usingInflateStream
, 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 ^^.
The text was updated successfully, but these errors were encountered: