Skip to content

mojo-zstd v0.4.0

Latest

Choose a tag to compare

@amarbarosys amarbarosys released this 26 Nov 05:04
· 1 commit to main since this release

mojo-zstd v0.4.0

Released: 2026-11-26 · Commit: tag zstd-v0.4.0 · Previous: v0.3.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

  • Faster decoding: 0.72 to 0.82x libzstd's speed at level 3 (v0.3.0: 0.64 to 0.70x); executables +10%, source text
    +11%, JSON +21% on their own.
  • decompress_into(data, out) decodes into a buffer you keep, so a decode loop does not allocate per call.

Changes

Added

  • zstd.decompress_into(data: Span[UInt8, _], mut out: List[UInt8]): decompress into out's memory; out is
    empty after an error. decompress is unchanged for callers.

Changed

  • Sequence execution copies literals 32 bytes and far matches 16 bytes unconditionally before any loop, as libzstd
    does, which saves a mispredicted loop exit on most sequences.
  • tests/bench31.mojo times decompress_into, so both sides of the throughput table reuse their output buffer.

Verified

Check Result
scripts/ci.sh (oracle, golden vectors, mutants, size gate, stream RSS, rebase, API incl. decompress_into reuse and error case, README example) PASS all on monorepo and in a fresh worktree off origin/main
decode-only A/B, best of 3x7 exe 1067 -> 1180, C sources 1544 -> 1725, JSON 1094 -> 1340 MB/s
scripts/bench31.sh, best of two runs, load 7 to 9 decompress 0.73 / 0.72 / 0.79 / 0.79 / 0.82 of libzstd (random, repeated, exe, C sources, JSON)
GitHub CI on main success (run 45755809063)

Known limits

  • zstd -b decodes frames without a checksum; ours verify XXH64 (24 GB/s), which is most of the gap on random and
    repeated input.
  • On sequence-heavy input the match copy waits on literal bytes it just stored; closing that needs libzstd's
    lookahead decode loop.
  • 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; decompress is unchanged

Commits

  • dc12d588 docs(zstd): decompress_into and the decoder round in README, api, perf, skill
  • 86f0d5ed perf(zstd): unconditional first copy of literals and far matches
  • e5ebaeef feat(zstd): decompress_into reuses the caller's buffer