Repository navigation
mojo-zstd v0.3.0
mojo-zstd v0.3.0
Released: 2026-11-26 · Commit: tag zstd-v0.3.0 · Previous: v0.2.0
What it does
zstd and lz4 frame compression for Mojo, in pure Mojo: one-shot compress/decompress, and
streaming zstd files or buffers through a 128 KiB window. No C library, no foreign calls, no linker flag.
Highlights
- Much faster at level 3 (issue #31): compress runs at 0.76 to 0.96x libzstd's speed and decompress at 0.64 to 0.70x
on random, repetitive, binary, source and JSON input. In v0.2.0 the issue measured compress 1.3 to 6.8x and
decompress 1.6 to 4.6x slower than libzstd. - Same output: compressed sizes are byte-count identical to v0.2.0 at every level, and decoding still accepts and
rejects exactly what libzstd 1.5.7 does. - Higher levels got faster too: level 9 49 -> 42 ms and level 19 2750 -> 2601 ms on 4 MiB of text.
Changes
Added
scripts/bench31.shandtests/bench31.mojo: level-3 throughput of five inputs againstzstd -b3 --single-thread.
Changed
- Decoder: overlapping matches, literals and short matches copy 16 bytes per step; the four Huffman streams decode
side by side;decompressreserves the frame's declared content size in one step (capped at 64 MiB past what is
decoded, so a lying header stays cheap) instead of growing by doubling. - Encoder: flat literals go raw without building a Huffman table (libzstd's heuristic); match-free flat blocks skip
entropy work; sequences are stored with 16-byte literal copies; block-split fingerprints use raw pointers.
Fixed
- Builds on Mojo 1.3 nightly (interior origins,
ZstdReader/ZstdWriter).
Verified
| Check | Result |
|---|---|
scripts/ci.sh (oracle 2000 cases + golden vectors, 3 planted mutants and 2 FSE mutants rejected, size within 5% of libzstd at every level, stream RSS, rebase, API, README example) |
PASS all, on the release tree and in a fresh worktree off origin/main |
scripts/bench31.sh, 7800X3D, load 6.7 |
compress 0.89 / 0.96 / 0.76 / 0.81 / 0.78, decompress 0.70 / 0.70 / 0.67 / 0.68 / 0.64 of libzstd (random, repeated, exe, C sources, JSON) |
scripts/bench.sh, 32 MiB text, 3 runs |
zstd c 70-72 ms, d 45-50 ms (v0.2.0: 84-95, 48-73); sizes unchanged |
GitHub CI on main after the push |
success (run 45749869665) |
Known limits
- Decompression is still 0.64 to 0.70x libzstd: the sequence loop, double-symbol Huffman tables and the dfast match
finder are the open items. - Peak RSS of
decompresson 32 MiB is 6 MB above v0.2.0 (one-step reservation of the declared size). zstd.decompressallocates a new output per call;zstd -breuses its buffer, so part of the remaining decode gap
is allocation and page faults.- Not covered: dictionaries, multithreading, long-distance matching, the lz4 block format, lz4 levels.
Upgrade / run
pixi upgrade mojo-zstd # channel https://prefix.dev/amarbaro/amarbaro; API unchanged
Commits
7c9aace9docs(zstd): level-3 throughput in README, skill and changelog49bfefc0docs(zstd): level-3 throughput table against libzstde39a62e2perf(zstd): decode the four Huffman streams side by side9c8c94a3perf(zstd): store sequences with 16-byte literal copies and unchecked arrays44222ad9perf(zstd): 16-byte steps for sequence literals and short matchesf675b2a8perf(zstd): split fingerprints through raw pointersc37e06afperf(zstd): raw block without entropy work for match-free flat input; one output reservatione638009dperf(zstd): decode into a buffer sized from the frame content sizef9ac4168test(zstd): level-3 throughput harness against libzstd2d105ba9perf(zstd): 16-byte overlap match copy; skip Huffman on flat literalsfc09c3cadocs(readme): -I paths match the monorepo folders3d7469ffdocs(readme): badges and links point to the monorepo3f7bc623fix: build on Mojo nightly 2026111905 (interior origins)219544a7test(oracle): require system libzstd 1.5.7, fail by name otherwiseff51b7ceRevert "test(oracle): judge corrupted frames with the bundled libzstd 1.5.7"dee03da4test(oracle): judge corrupted frames with the bundled libzstd 1.5.7aa119959test(stream): RSS growth limit +2 MB, above measured runner noisee13974cfchore: ignore lane exchange dird0fc0b92chore: uv.lock carries version 0.2.04af6aaaffix: ZstdReader and ZstdWriter build on Mojo 1.3 nightly5a0b7c09test: malformed-input fuzz for the zstd and lz4 decoders