Skip to content

Big slow-down in WebAssembly (wasm) #55

@mpizenberg

Description

@mpizenberg

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 ^^.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions