Choose a codec with measured costs

On a 64 KiB documentation sample, LZ4 used 4.58 million instructions to compress, gzip level 1 used 13.65 million, and gzip level 6 used 37.17 million. The gzip outputs were smaller for this input.

Compare the output size and the work to create it

One Wasm64 benchmark canister ran the selected SIMD LZ4 implementation and gzip through flate2 with miniz_oxide. It measured documentation, synthetic forum JSON, pseudorandom bytes and repetitive logs at four sizes from 128 bytes to 1 MiB, plus two complete Wasm modules. The sizes compare bare LZ4 blocks with complete gzip streams, including gzip framing and CRC.

For the 64 KiB documentation sample, LZ4 kept 55.7% of the original bytes, gzip level 1 kept 48.4%, and gzip level 6 kept 34.9%. At one payload per update, LZ4 compressed the sample in 4.58 million instructions and decompressed it in 1.37 million. Gzip level 6 spent 37.17 million to compress and 6.72 million to decompress. A read-heavy application can weigh decode cost separately from how often it writes.

Use your payloads and count the whole call

Each cost is the mean of two measured updates after a warmup. The report separates the codec interval from the complete call, which includes SDK entry and verifies every output by decoding it. The complete checked compression call for that sample took 8.98 million instructions for LZ4, 23.56 million for gzip level 1 and 45.97 million for gzip level 6.

All three encoders expanded the pseudorandom inputs. LZ4 produced the smallest output on the repetitive 64 KiB log. The corpus gives you cases to try on your own data, with instruction cost, output size and decode cost measured separately.

Code, tests, and related material