AIFeed

Show HN: misa77 – Up to 3x faster decompression than zstd, with better ratios

Original text(via Hacker News)

misa77 (0.9.0)

misa77 is an LZ-based compressor that targets the write-once, read-many niche. In particular, it aims to satisfy the following criteria:

  • Extremely high decompression throughput (single-threaded and in-memory).
  • Good compression ratios relative to decode throughput. For reference, misa77 levels that correspond to LZ4 and zstd-class ratios decode roughly 2 times faster than their counterparts.
  • Constant memory use during compression, regardless of input size.

Slow compression is the obvious tradeoff that we make to achieve the above.

Decompression is guaranteed to be safe in the case of corrupt/malicious input (i.e. the decompressor terminates gracefully, and does not access out-of-bounds memory or engage in any other UB) .

Benchmarks

A terse summary of misa77's performance would be that relative to its competitors (LZ4 class codecs for levels 1 to 6, and zstd/brotli/xz for levels 11 to 13), it encodes somewhat slower, gets similar ratios, but decodes much faster.

Some results on specific corpora follow. For more detailed and cross-platform results, see BENCHMARKS.md.

The benchmarks below were run on the following setup:

  • CPU: Intel(R) Core(TM) i7-14650HX (@2.2 GHz) (Intel Turbo disabled).
  • Single threaded, pinned to a single performance core.
  • CPU governor set to performance, uncore frequency pinned at its maximum.

The benchmarking harness used was lzbench. misa77 has also been merged into TurboBench, and the results below can be reproduced through both harnesses.

Silesia Corpus

This corpus can be found here. It contains 12 files, totaling 212 MB, covering text, source code, databases, executables, and medical images. It is the standard (albeit outdated) corpus for comparing general-purpose compressors.

Decode throughput vs compression ratio on silesia.tar (Intel)
Decode throughput vs compression ratio on silesia.tar (Intel)

The takeaway is that levels 3-6 dominate LZ4 (and other codecs in this class) on decode speed. Level 6 in particular gets smaller ratios and decodes ~2x faster (...and encodes much slower). Levels 11-13 get ratios similar to those of zstd's levels 11 to 22, while decoding about 2.5 to 3 times faster.

Note: lzbench lists misa77 as two codecs, as its levels are not contiguous. misa77 is levels 1 to 6 and misa77ec is levels 11 to 13.

Compressor nameCompressionDecompress.RatioFilename
misa77 0.9.0 -1233 MB/s4495 MB/s46.74silesia.tar
misa77 0.9.0 -2168 MB/s5157 MB/s44.28silesia.tar
misa77 0.9.0 -371.9 MB/s5909 MB/s42.59silesia.tar
misa77 0.9.0 -442.9 MB/s5227 MB/s40.33silesia.tar
misa77 0.9.0 -510.6 MB/s5160 MB/s37.76silesia.tar
misa77 0.9.0 -61.79 MB/s5334 MB/s32.34silesia.tar
misa77ec 0.9.0 -1133.1 MB/s2445 MB/s27.38silesia.tar
misa77ec 0.9.0 -125.81 MB/s2496 MB/s25.83silesia.tar
misa77ec 0.9.0 -131.39 MB/s2633 MB/s24.82silesia.tar
lz4 1.11.0383 MB/s2551 MB/s47.32silesia.tar
lz4hc 1.11.0 -921.2 MB/s2480 MB/s36.75silesia.tar
lz4hc 1.11.0 -127.80 MB/s2563 MB/s36.45silesia.tar
lzav 7.2 -1341 MB/s1697 MB/s39.23silesia.tar
lzav 7.2 -269.6 MB/s1719 MB/s34.54silesia.tar
zxc 1.0.0 -3122 MB/s3719 MB/s46.59silesia.tar
zxc 1.0.0 -554.5 MB/s3250 MB/s40.81silesia.tar
zxc 1.0.0 -75.11 MB/s1989 MB/s33.09silesia.tar
zstd 1.5.7 -1297 MB/s905 MB/s34.54silesia.tar
zstd 1.5.7 -598.6 MB/s853 MB/s29.60silesia.tar
zstd 1.5.7 -1126.7 MB/s976 MB/s27.35silesia.tar
zstd 1.5.7 -156.86 MB/s997 MB/s26.83silesia.tar
zstd 1.5.7 -192.32 MB/s870 MB/s24.93silesia.tar
zstd 1.5.7 -221.51 MB/s813 MB/s24.67silesia.tar
zlib 1.4 -97.41 MB/s199 MB/s31.91silesia.tar
libdeflate 1.26 -123.08 MB/s599 MB/s30.51silesia.tar
brotli 1.2.0 -540.5 MB/s284 MB/s28.11silesia.tar
brotli 1.2.0 -812.7 MB/s309 MB/s26.96silesia.tar
xz 5.8.4 -62.30 MB/s78.1 MB/s23.35silesia.tar
xz 5.8.4 -92.01 MB/s79.1 MB/s23.01silesia.tar
bzip3 1.5.4 -59.38 MB/s9.79 MB/s22.29silesia.tar

Game Asset Corpus

There's no standard corpus for this, so I unwrapped the archives of some games (14 games, using 12 different engines), and put together a corpus containing the following data types: textures (33 %), geometry (15 %), levels (14 %), engine packages (13 %), other raster data (10 %), text and tables (9 %) and animation (6 %). It's about 263 MB, and games usually compress data in small independent blocks, so I've included results at 256 KiB and 64 KiB block framings.

Decode throughput vs compression ratio on a game asset corpus (Intel), whole file and in 256 KiB and 64 KiB blocks
Decode throughput vs compression ratio on a game asset corpus (Intel), whole file and in 256 KiB and 64 KiB blocks

The takeaways are quite similar to those for silesia, except that levels 12 and 13 get better ratios than zstd here. Also, the relative placement of codecs here is not that sensitive to blocked framing (although their absolute ratios do worsen as block size reduces).

Compressor nameCompressionDecompress.Compr. sizeRatio
misa77 0.9.0 -1330 MB/s4255 MB/s15070532357.24
misa77 0.9.0 -2225 MB/s4865 MB/s14576758155.36
misa77 0.9.0 -385.5 MB/s5700 MB/s14172584053.83
misa77 0.9.0 -437.0 MB/s4501 MB/s13524401851.36
misa77 0.9.0 -510.9 MB/s4567 MB/s12991035849.34
misa77 0.9.0 -61.94 MB/s5417 MB/s11637240244.20
misa77ec 0.9.0 -1134.0 MB/s2218 MB/s9634322536.59
misa77ec 0.9.0 -126.92 MB/s2179 MB/s9091808334.53
misa77ec 0.9.0 -131.68 MB/s2279 MB/s8602372632.67
lz4 1.11.0534 MB/s2980 MB/s14282381354.24
lz4hc 1.11.0 -923.6 MB/s2746 MB/s12216533846.40
lz4hc 1.11.0 -126.70 MB/s2834 MB/s12173282946.23
lzav 7.2 -1506 MB/s2248 MB/s13286868050.46
lzav 7.2 -293.5 MB/s1931 MB/s12176178746.24
zxc 1.0.0 -3184 MB/s4125 MB/s15490206458.83
zxc 1.0.0 -557.7 MB/s3402 MB/s13231223150.25
zxc 1.0.0 -77.25 MB/s1724 MB/s11722959044.52
zstd 1.5.7 -1360 MB/s792 MB/s11461634043.53
zstd 1.5.7 -5100 MB/s748 MB/s10436504839.64
zstd 1.5.7 -1136.0 MB/s784 MB/s10065195138.23
zstd 1.5.7 -1511.4 MB/s791 MB/s10022691738.07
zstd 1.5.7 -193.80 MB/s602 MB/s9174726634.84
zstd 1.5.7 -222.39 MB/s590 MB/s9164364134.81
zlib 1.4 -94.25 MB/s182 MB/s10699039040.63
libdeflate 1.26 -124.18 MB/s466 MB/s10340031539.27
brotli 1.2.0 -540.6 MB/s200 MB/s9894197437.58
brotli 1.2.0 -89.93 MB/s200 MB/s9778659537.14
xz 5.8.4 -63.07 MB/s52.8 MB/s8048777230.57
xz 5.8.4 -92.65 MB/s52.8 MB/s8031292430.50
bzip3 1.5.4 -58.69 MB/s8.92 MB/s9609384136.50
Compressor nameCompressionDecompress.Compr. sizeRatio
misa77 0.9.0 -1336 MB/s4190 MB/s15189771057.69
misa77 0.9.0 -2228 MB/s4789 MB/s14710066955.87
misa77 0.9.0 -385.2 MB/s5602 MB/s14315575654.37
misa77 0.9.0 -438.5 MB/s4403 MB/s13673210251.93
misa77 0.9.0 -59.97 MB/s4466 MB/s13156567649.97
misa77 0.9.0 -62.59 MB/s5293 MB/s12171308846.23
misa77ec 0.9.0 -1124.0 MB/s2081 MB/s10257373238.96
misa77ec 0.9.0 -123.65 MB/s2052 MB/s9599484836.46
misa77ec 0.9.0 -131.57 MB/s2188 MB/s9121829234.64
lz4 1.11.0540 MB/s2982 MB/s14345681054.48
lz4hc 1.11.0 -925.2 MB/s2738 MB/s12367201246.97
lz4hc 1.11.0 -127.28 MB/s2828 MB/s12326088746.81
lzav 7.2 -1492 MB/s2275 MB/s13847161152.59
lzav 7.2 -2110 MB/s1938 MB/s12911121049.04
zxc 1.0.0 -3187 MB/s3302 MB/s15319999458.18
zxc 1.0.0 -559.6 MB/s2728 MB/s13292451350.48
zxc 1.0.0 -77.31 MB/s1463 MB/s11752017944.63
zstd 1.5.7 -1343 MB/s761 MB/s11507666243.71
zstd 1.5.7 -594.3 MB/s745 MB/s10893141041.37
zstd 1.5.7 -1119.8 MB/s753 MB/s10373570939.40
zstd 1.5.7 -157.79 MB/s576 MB/s9758709337.06
zstd 1.5.7 -193.76 MB/s554 MB/s9666358736.71
zstd 1.5.7 -222.99 MB/s553 MB/s9665113136.71
zlib 1.4 -94.45 MB/s181 MB/s10752519440.84
libdeflate 1.26 -124.13 MB/s459 MB/s10403343839.51
brotli 1.2.0 -538.3 MB/s191 MB/s10009946538.02
brotli 1.2.0 -823.3 MB/s190 MB/s9951655837.80
xz 5.8.4 -63.78 MB/s49.5 MB/s8522554432.37
xz 5.8.4 -92.43 MB/s48.4 MB/s8522554432.37
bzip3 1.5.4 -58.64 MB/s9.56 MB/s9452212835.90
Compressor nameCompressionDecompress.Compr. sizeRatio
misa77 0.9.0 -1343 MB/s4112 MB/s15559150659.09
misa77 0.9.0 -2229 MB/s4650 MB/s15124904057.44
misa77 0.9.0 -383.8 MB/s5398 MB/s14747132056.01
misa77 0.9.0 -437.5 MB/s4191 MB/s14132960153.68
misa77 0.9.0 -512.1 MB/s4257 MB/s13672342751.93
misa77 0.9.0 -62.77 MB/s5065 MB/s12632113847.98
misa77ec 0.9.0 -1133.3 MB/s1878 MB/s10709743340.67
misa77ec 0.9.0 -123.78 MB/s1882 MB/s10142482338.52
misa77ec 0.9.0 -131.85 MB/s2028 MB/s9637261036.60
lz4 1.11.0442 MB/s2297 MB/s14394379754.67
lz4hc 1.11.0 -931.5 MB/s2721 MB/s12830875248.73
lz4hc 1.11.0 -129.83 MB/s2811 MB/s12796509148.60
lzav 7.2 -1460 MB/s1933 MB/s14068593053.43
lzav 7.2 -2120 MB/s1982 MB/s13539981751.42
zxc 1.0.0 -3227 MB/s3145 MB/s15334181558.24
zxc 1.0.0 -577.5 MB/s2624 MB/s13704965552.05
zxc 1.0.0 -77.80 MB/s1186 MB/s12114625446.01
zstd 1.5.7 -1349 MB/s730 MB/s11795614744.80
zstd 1.5.7 -597.0 MB/s651 MB/s10991828041.75
zstd 1.5.7 -1123.0 MB/s707 MB/s10786659740.97
zstd 1.5.7 -159.25 MB/s574 MB/s10272881039.02
zstd 1.5.7 -193.42 MB/s552 MB/s10165804638.61
zstd 1.5.7 -222.53 MB/s552 MB/s10163331438.60
zlib 1.4 -95.13 MB/s176 MB/s10901528041.40
libdeflate 1.26 -124.28 MB/s440 MB/s10579468340.18
brotli 1.2.0 -537.9 MB/s180 MB/s10334203839.25
brotli 1.2.0 -824.9 MB/s177 MB/s10294790339.10
xz 5.8.4 -63.83 MB/s47.0 MB/s9029387234.29
xz 5.8.4 -91.53 MB/s45.8 MB/s9029387234.29
bzip3 1.5.4 -58.42 MB/s9.11 MB/s9897655037.59

Levels

TLDR: I recommend using one of levels 3, 11, 12, or 13 depending on your requirements.

misa77 is really two classes of compressors bundled into one library:

  • Levels 1-6 involve simple LZ compression with no entropy coding or preprocessing. Competitors here would be LZ4, LZSSE, Lizard, etc.
  • Levels 11-13 involve LZ compression along with possible use of entropy coding, delta coding, and some other tricks. Competitors here would be zstd, brotli, etc.

Within a class, levels are ordered by compression effort. For most shapes of data, encode time increases and ratio decreases with increasing level (within a class), but decompression throughput is not similarly monotonic.

LevelDescriptionRatioEncode vs L3Decode vs L3Encoder memoryFormat
1fastest compression (not recommended as slow to decode)46.743.2x76%1 MBlight
2fast compression, lz4-class ratio44.282.3x87%1 MBlight
3default, fastest decode42.591x100%1 MBlight
4better ratio, still cheap to encode40.330.60x88%3 MBlight
5best ratio in the light format37.760.15x87%29 MBlight
6best ratio without entropy coding32.340.025x90%73 MBheavy
11entropy-coded, fast compression27.380.46x41%35 MBentropy
12entropy-coded, better ratio25.830.081x42%72 MBentropy
13entropy-coded, best ratio overall24.820.019x45%164 MBentropy
  • Ratio is as measured on silesia.tar in the Intel run.
  • The Encode/Decode vs L3 columns are throughput relative to level 3, from the same run.
  • Levels 1 to 5 emit the light format, level 6 emits the heavy format and levels 11 to 13 emit the entropy format (see docs/format.md).
  • Encoder memory is the compressor's own working state (disjoint from the caller's input and output buffers). Levels 5 and above need less for inputs smaller than their internal block or window (level 13 uses about 11 MB for a 64 KB input and 52 MB for a 1 MB input, and level 11 about 4 MB and 30 MB).
  • Decompression needs no working memory at levels 1 to 6, and the decoder for levels 11 to 13 allocates 1.4 MB of scratch space per call.

Requirements

For the library:

  • A C++20 compiler (both GCC and Clang are fine).
  • CMake >= 3.20.
  • A little-endian 64-bit system.

For the CLI:

  • The misa CLI needs POSIX (Linux, macOS).

Note: On x86-64, AVX2/SSE2 are selected at runtime. ARM has a NEON path. On x86-64 and ARM64 with GCC or Clang, the decoders use hand-written assembly kernels (you can pass -DMISA77_ASM=OFF to use the C++ decoders instead, but I strongly recommend not doing this).

Building


        cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
      

This produces the misa CLI at build/misa. For a binary tuned to the machine you'll run it on, add -DMISA77_MARCH=native (I recommend this). To run the round-trip test:


        ctest --test-dir build
      

Note: if you build the library with your own build system on x86-64 instead of the CMakeLists.txt from this repo, ensure the following two things.

  • src/isa/target_sse2.cpp (or target_portable.cpp) must come before src/isa/target_avx2.cpp on the link line or in the archive.
  • LTO must stay off for the library.

Library Usage

The build produces a static library (CMake target misa77::misa77) with a small C++ API in misa77/misa77.h. The easiest integration is a git submodule (or CMake FetchContent) plus:


        add_subdirectory(misa77)
target_link_libraries(your_app PRIVATE misa77::misa77)
      

Alternatively, install it (cmake --install build --prefix <dir>) and use:


        find_package(misa77 REQUIRED)
target_link_libraries(your_app PRIVATE misa77::misa77)
      

Pass -DMISA77_BUILD_CLI=OFF if you only want the library.

Sample usage:


        #include <misa77/misa77.h>
#include <vector>

// compress (pick a level with misa77::config(N) where N is a valid level, default is 3), returns 0 on failure
misa77::config cfg;
std::vector<uint8_t> compressed(misa77::compress_bound(input_size, cfg));
uint64_t csize = misa77::compress(input, input_size, compressed.data(), compressed.size(), cfg);
compressed.resize(csize);

// decompress, returns original_size on success
uint64_t original_size = misa77::decompressed_size(compressed.data());
std::vector<uint8_t> output(misa77::decompressed_buffer_bound(original_size));
// returns 0 on invalid input
uint64_t written = misa77::decompress(compressed.data(), csize, output.data(), output.size());
      

Two things to keep in mind:

  • You must size the destination buffers with compress_bound / decompressed_buffer_bound, passing compress_bound the same config you compress with (the bound depends on the level's format).
  • The size you pass to misa77::decompress must be the exact size of the compressed stream (what compress returned), and not the size of the buffer holding it.

The experimental modes are declared in misa77/experimental.h, with usage documented in comments (these keep changing frequently so I don't wanna "formally" document them here just yet). You probably shouldn't be using them anyway.

CLI Usage

misa is a single, dependency-free binary with two file-based subcommands, and a benchmark mode. It operates on single files only (there's no directory or pipe support, so tar first if you need those).


        misa compress   FILE          # -> FILE.misa77
misa decompress FILE.misa77   # -> FILE
      

misa compress takes -l N / --level N to pick the compression level (default is 3). Everywhere, -o PATH sets the output path and -f overwrites without asking.


        misa compress -l 12 enwik8               # enwik8 -> enwik8.misa77
misa decompress enwik8.misa77 -f         # back to enwik8
      

misa bench FILE compresses and decompresses a file in memory, and prints the sizes and throughput of each level (nothing is written to disk). -l N or -l A:B restricts it to one level or a range of levels, and -t SECONDS sets how long decompression is timed for at each level (default 3). Compression is timed over a single pass (as it's quite slow anyway), and decompression over the fastest of multiple passes.


        $ misa bench -l 1:3 silesia.tar
 1#silesia.tar    :  211957760 ->   99075595 ( 46.74%),   233 MB/s,  4399 MB/s
 2#silesia.tar    :  211957760 ->   93849014 ( 44.28%),   169 MB/s,  5000 MB/s
 3#silesia.tar    :  211957760 ->   90281695 ( 42.59%),  71.7 MB/s,  5684 MB/s
      

Documentation

The underlying stream formats (used by the library functions) and the container format for .misa77 files (produced by the CLI) can be found in docs/.

Status

  • misa77's format may change unexpectedly as it's still v0.x.y.
  • It's been through local fuzzing with ASan/UBSan, broader hardening is ongoing.

Note: misa77 has evolved out of a less polished endeavour to learn performance engineering, and its history can be found in this archived repository.

Acknowledgement

Inspiration has been taken from:

  • Various people on encode.su

Lastly, the following models helped a lot with every step of the process, including independently suggesting ideas/techniques that I wouldn't have thought of. Without their assistance, development would have been far slower, and I would likely not have explored all the paths that I did end up exploring (some of which were productive and some of which weren't).

  • Claude Fable 5
  • Claude Opus 5
  • Claude Opus 5.5
  • Claude Fable 5.2

License

MIT (see LICENSE).

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Hacker News
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗