Skip to content

mojo-zstd v0.3.0

Choose a tag to compare

@amarbarosys amarbarosys released this 26 Nov 03:56
· 5 commits to main since this release

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.sh and tests/bench31.mojo: level-3 throughput of five inputs against zstd -b3 --single-thread.

Changed

  • Decoder: overlapping matches, literals and short matches copy 16 bytes per step; the four Huffman streams decode
    side by side; decompress reserves 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 decompress on 32 MiB is 6 MB above v0.2.0 (one-step reservation of the declared size).
  • zstd.decompress allocates a new output per call; zstd -b reuses 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

  • 7c9aace9 docs(zstd): level-3 throughput in README, skill and changelog
  • 49bfefc0 docs(zstd): level-3 throughput table against libzstd
  • e39a62e2 perf(zstd): decode the four Huffman streams side by side
  • 9c8c94a3 perf(zstd): store sequences with 16-byte literal copies and unchecked arrays
  • 44222ad9 perf(zstd): 16-byte steps for sequence literals and short matches
  • f675b2a8 perf(zstd): split fingerprints through raw pointers
  • c37e06af perf(zstd): raw block without entropy work for match-free flat input; one output reservation
  • e638009d perf(zstd): decode into a buffer sized from the frame content size
  • f9ac4168 test(zstd): level-3 throughput harness against libzstd
  • 2d105ba9 perf(zstd): 16-byte overlap match copy; skip Huffman on flat literals
  • fc09c3ca docs(readme): -I paths match the monorepo folders
  • 3d7469ff docs(readme): badges and links point to the monorepo
  • 3f7bc623 fix: build on Mojo nightly 2026111905 (interior origins)
  • 219544a7 test(oracle): require system libzstd 1.5.7, fail by name otherwise
  • ff51b7ce Revert "test(oracle): judge corrupted frames with the bundled libzstd 1.5.7"
  • dee03da4 test(oracle): judge corrupted frames with the bundled libzstd 1.5.7
  • aa119959 test(stream): RSS growth limit +2 MB, above measured runner noise
  • e13974cf chore: ignore lane exchange dir
  • d0fc0b92 chore: uv.lock carries version 0.2.0
  • 4af6aaaf fix: ZstdReader and ZstdWriter build on Mojo 1.3 nightly
  • 5a0b7c09 test: malformed-input fuzz for the zstd and lz4 decoders