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

Source: github.com
143 points by nonadhocproblem 7 hours ago on hackernews | 44 comments

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:

  1. Extremely high decompression throughput (single-threaded and in-memory).
  2. 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.
  3. 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)

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.

Table: silesia.tar (Intel)
Compressor name Compression Decompress. Ratio Filename
misa77 0.9.0 -1 233 MB/s 4495 MB/s 46.74 silesia.tar
misa77 0.9.0 -2 168 MB/s 5157 MB/s 44.28 silesia.tar
misa77 0.9.0 -3 71.9 MB/s 5909 MB/s 42.59 silesia.tar
misa77 0.9.0 -4 42.9 MB/s 5227 MB/s 40.33 silesia.tar
misa77 0.9.0 -5 10.6 MB/s 5160 MB/s 37.76 silesia.tar
misa77 0.9.0 -6 1.79 MB/s 5334 MB/s 32.34 silesia.tar
misa77ec 0.9.0 -11 33.1 MB/s 2445 MB/s 27.38 silesia.tar
misa77ec 0.9.0 -12 5.81 MB/s 2496 MB/s 25.83 silesia.tar
misa77ec 0.9.0 -13 1.39 MB/s 2633 MB/s 24.82 silesia.tar
lz4 1.11.0 383 MB/s 2551 MB/s 47.32 silesia.tar
lz4hc 1.11.0 -9 21.2 MB/s 2480 MB/s 36.75 silesia.tar
lz4hc 1.11.0 -12 7.80 MB/s 2563 MB/s 36.45 silesia.tar
lzav 7.2 -1 341 MB/s 1697 MB/s 39.23 silesia.tar
lzav 7.2 -2 69.6 MB/s 1719 MB/s 34.54 silesia.tar
zxc 1.0.0 -3 122 MB/s 3719 MB/s 46.59 silesia.tar
zxc 1.0.0 -5 54.5 MB/s 3250 MB/s 40.81 silesia.tar
zxc 1.0.0 -7 5.11 MB/s 1989 MB/s 33.09 silesia.tar
zstd 1.5.7 -1 297 MB/s 905 MB/s 34.54 silesia.tar
zstd 1.5.7 -5 98.6 MB/s 853 MB/s 29.60 silesia.tar
zstd 1.5.7 -11 26.7 MB/s 976 MB/s 27.35 silesia.tar
zstd 1.5.7 -15 6.86 MB/s 997 MB/s 26.83 silesia.tar
zstd 1.5.7 -19 2.32 MB/s 870 MB/s 24.93 silesia.tar
zstd 1.5.7 -22 1.51 MB/s 813 MB/s 24.67 silesia.tar
zlib 1.4 -9 7.41 MB/s 199 MB/s 31.91 silesia.tar
libdeflate 1.26 -12 3.08 MB/s 599 MB/s 30.51 silesia.tar
brotli 1.2.0 -5 40.5 MB/s 284 MB/s 28.11 silesia.tar
brotli 1.2.0 -8 12.7 MB/s 309 MB/s 26.96 silesia.tar
xz 5.8.4 -6 2.30 MB/s 78.1 MB/s 23.35 silesia.tar
xz 5.8.4 -9 2.01 MB/s 79.1 MB/s 23.01 silesia.tar
bzip3 1.5.4 -5 9.38 MB/s 9.79 MB/s 22.29 silesia.tar
bzip2 1.0.8 -9 9.11 MB/s 26.7 MB/s 25.75 silesia.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

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

Table: game asset corpus, whole file (Intel)
Compressor name Compression Decompress. Compr. size Ratio
misa77 0.9.0 -1 330 MB/s 4255 MB/s 150705323 57.24
misa77 0.9.0 -2 225 MB/s 4865 MB/s 145767581 55.36
misa77 0.9.0 -3 85.5 MB/s 5700 MB/s 141725840 53.83
misa77 0.9.0 -4 37.0 MB/s 4501 MB/s 135244018 51.36
misa77 0.9.0 -5 10.9 MB/s 4567 MB/s 129910358 49.34
misa77 0.9.0 -6 1.94 MB/s 5417 MB/s 116372402 44.20
misa77ec 0.9.0 -11 34.0 MB/s 2218 MB/s 96343225 36.59
misa77ec 0.9.0 -12 6.92 MB/s 2179 MB/s 90918083 34.53
misa77ec 0.9.0 -13 1.68 MB/s 2279 MB/s 86023726 32.67
lz4 1.11.0 534 MB/s 2980 MB/s 142823813 54.24
lz4hc 1.11.0 -9 23.6 MB/s 2746 MB/s 122165338 46.40
lz4hc 1.11.0 -12 6.70 MB/s 2834 MB/s 121732829 46.23
lzav 7.2 -1 506 MB/s 2248 MB/s 132868680 50.46
lzav 7.2 -2 93.5 MB/s 1931 MB/s 121761787 46.24
zxc 1.0.0 -3 184 MB/s 4125 MB/s 154902064 58.83
zxc 1.0.0 -5 57.7 MB/s 3402 MB/s 132312231 50.25
zxc 1.0.0 -7 7.25 MB/s 1724 MB/s 117229590 44.52
zstd 1.5.7 -1 360 MB/s 792 MB/s 114616340 43.53
zstd 1.5.7 -5 100 MB/s 748 MB/s 104365048 39.64
zstd 1.5.7 -11 36.0 MB/s 784 MB/s 100651951 38.23
zstd 1.5.7 -15 11.4 MB/s 791 MB/s 100226917 38.07
zstd 1.5.7 -19 3.80 MB/s 602 MB/s 91747266 34.84
zstd 1.5.7 -22 2.39 MB/s 590 MB/s 91643641 34.81
zlib 1.4 -9 4.25 MB/s 182 MB/s 106990390 40.63
libdeflate 1.26 -12 4.18 MB/s 466 MB/s 103400315 39.27
brotli 1.2.0 -5 40.6 MB/s 200 MB/s 98941974 37.58
brotli 1.2.0 -8 9.93 MB/s 200 MB/s 97786595 37.14
xz 5.8.4 -6 3.07 MB/s 52.8 MB/s 80487772 30.57
xz 5.8.4 -9 2.65 MB/s 52.8 MB/s 80312924 30.50
bzip3 1.5.4 -5 8.69 MB/s 8.92 MB/s 96093841 36.50
bzip2 1.0.8 -9 6.96 MB/s 22.4 MB/s 101586954 38.58
Table: game asset corpus, 256 KiB blocks (Intel)
Compressor name Compression Decompress. Compr. size Ratio
misa77 0.9.0 -1 336 MB/s 4190 MB/s 151897710 57.69
misa77 0.9.0 -2 228 MB/s 4789 MB/s 147100669 55.87
misa77 0.9.0 -3 85.2 MB/s 5602 MB/s 143155756 54.37
misa77 0.9.0 -4 38.5 MB/s 4403 MB/s 136732102 51.93
misa77 0.9.0 -5 9.97 MB/s 4466 MB/s 131565676 49.97
misa77 0.9.0 -6 2.59 MB/s 5293 MB/s 121713088 46.23
misa77ec 0.9.0 -11 24.0 MB/s 2081 MB/s 102573732 38.96
misa77ec 0.9.0 -12 3.65 MB/s 2052 MB/s 95994848 36.46
misa77ec 0.9.0 -13 1.57 MB/s 2188 MB/s 91218292 34.64
lz4 1.11.0 540 MB/s 2982 MB/s 143456810 54.48
lz4hc 1.11.0 -9 25.2 MB/s 2738 MB/s 123672012 46.97
lz4hc 1.11.0 -12 7.28 MB/s 2828 MB/s 123260887 46.81
lzav 7.2 -1 492 MB/s 2275 MB/s 138471611 52.59
lzav 7.2 -2 110 MB/s 1938 MB/s 129111210 49.04
zxc 1.0.0 -3 187 MB/s 3302 MB/s 153199994 58.18
zxc 1.0.0 -5 59.6 MB/s 2728 MB/s 132924513 50.48
zxc 1.0.0 -7 7.31 MB/s 1463 MB/s 117520179 44.63
zstd 1.5.7 -1 343 MB/s 761 MB/s 115076662 43.71
zstd 1.5.7 -5 94.3 MB/s 745 MB/s 108931410 41.37
zstd 1.5.7 -11 19.8 MB/s 753 MB/s 103735709 39.40
zstd 1.5.7 -15 7.79 MB/s 576 MB/s 97587093 37.06
zstd 1.5.7 -19 3.76 MB/s 554 MB/s 96663587 36.71
zstd 1.5.7 -22 2.99 MB/s 553 MB/s 96651131 36.71
zlib 1.4 -9 4.45 MB/s 181 MB/s 107525194 40.84
libdeflate 1.26 -12 4.13 MB/s 459 MB/s 104033438 39.51
brotli 1.2.0 -5 38.3 MB/s 191 MB/s 100099465 38.02
brotli 1.2.0 -8 23.3 MB/s 190 MB/s 99516558 37.80
xz 5.8.4 -6 3.78 MB/s 49.5 MB/s 85225544 32.37
xz 5.8.4 -9 2.43 MB/s 48.4 MB/s 85225544 32.37
bzip3 1.5.4 -5 8.64 MB/s 9.56 MB/s 94522128 35.90
bzip2 1.0.8 -9 8.38 MB/s 23.6 MB/s 102207006 38.82
Table: game asset corpus, 64 KiB blocks (Intel)
Compressor name Compression Decompress. Compr. size Ratio
misa77 0.9.0 -1 343 MB/s 4112 MB/s 155591506 59.09
misa77 0.9.0 -2 229 MB/s 4650 MB/s 151249040 57.44
misa77 0.9.0 -3 83.8 MB/s 5398 MB/s 147471320 56.01
misa77 0.9.0 -4 37.5 MB/s 4191 MB/s 141329601 53.68
misa77 0.9.0 -5 12.1 MB/s 4257 MB/s 136723427 51.93
misa77 0.9.0 -6 2.77 MB/s 5065 MB/s 126321138 47.98
misa77ec 0.9.0 -11 33.3 MB/s 1878 MB/s 107097433 40.67
misa77ec 0.9.0 -12 3.78 MB/s 1882 MB/s 101424823 38.52
misa77ec 0.9.0 -13 1.85 MB/s 2028 MB/s 96372610 36.60
lz4 1.11.0 442 MB/s 2297 MB/s 143943797 54.67
lz4hc 1.11.0 -9 31.5 MB/s 2721 MB/s 128308752 48.73
lz4hc 1.11.0 -12 9.83 MB/s 2811 MB/s 127965091 48.60
lzav 7.2 -1 460 MB/s 1933 MB/s 140685930 53.43
lzav 7.2 -2 120 MB/s 1982 MB/s 135399817 51.42
zxc 1.0.0 -3 227 MB/s 3145 MB/s 153341815 58.24
zxc 1.0.0 -5 77.5 MB/s 2624 MB/s 137049655 52.05
zxc 1.0.0 -7 7.80 MB/s 1186 MB/s 121146254 46.01
zstd 1.5.7 -1 349 MB/s 730 MB/s 117956147 44.80
zstd 1.5.7 -5 97.0 MB/s 651 MB/s 109918280 41.75
zstd 1.5.7 -11 23.0 MB/s 707 MB/s 107866597 40.97
zstd 1.5.7 -15 9.25 MB/s 574 MB/s 102728810 39.02
zstd 1.5.7 -19 3.42 MB/s 552 MB/s 101658046 38.61
zstd 1.5.7 -22 2.53 MB/s 552 MB/s 101633314 38.60
zlib 1.4 -9 5.13 MB/s 176 MB/s 109015280 41.40
libdeflate 1.26 -12 4.28 MB/s 440 MB/s 105794683 40.18
brotli 1.2.0 -5 37.9 MB/s 180 MB/s 103342038 39.25
brotli 1.2.0 -8 24.9 MB/s 177 MB/s 102947903 39.10
xz 5.8.4 -6 3.83 MB/s 47.0 MB/s 90293872 34.29
xz 5.8.4 -9 1.53 MB/s 45.8 MB/s 90293872 34.29
bzip3 1.5.4 -5 8.42 MB/s 9.11 MB/s 98976550 37.59
bzip2 1.0.8 -9 8.24 MB/s 23.6 MB/s 106170403 40.32

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:

  1. Levels 1-6 involve simple LZ compression with no entropy coding or preprocessing. Competitors here would be LZ4, LZSSE, Lizard, etc.
  2. 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.

Level Description Ratio Encode vs L3 Decode vs L3 Encoder memory Format
1 fastest compression (not recommended as slow to decode) 46.74 3.2x 76% 1 MB light
2 fast compression, lz4-class ratio 44.28 2.3x 87% 1 MB light
3 default, fastest decode 42.59 1x 100% 1 MB light
4 better ratio, still cheap to encode 40.33 0.60x 88% 3 MB light
5 best ratio in the light format 37.76 0.15x 87% 29 MB light
6 best ratio without entropy coding 32.34 0.025x 90% 73 MB heavy
11 entropy-coded, fast compression 27.38 0.46x 41% 35 MB entropy
12 entropy-coded, better ratio 25.83 0.081x 42% 72 MB entropy
13 entropy-coded, best ratio overall 24.82 0.019x 45% 164 MB entropy
  • 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.

  1. 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.
  2. 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

  1. misa77's format may change unexpectedly as it's still v0.x.y.
  2. 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:

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 Opus 4.8
  • Claude Fable 5
  • Claude Opus 5
  • Claude Opus 5.5
  • Claude Fable 5.2

License

MIT (see LICENSE).