Skip to content

Experiment: use zrip's pure Rust decoder instead of C zstd - #10

Draft
Seldaek wants to merge 1 commit into
mainfrom
zrip
Draft

Seldaek wants to merge 1 commit into
mainfrom
zrip

Conversation

@Seldaek

@Seldaek Seldaek commented Nov 26, 2026

Copy link
Copy Markdown
Member

Experiment: replaces the vendored C zstd with zrip's pure Rust decoder (zrip-core + zrip-decode, both #![forbid(unsafe_code)], vendored in native/vendor so the offline Linux build keeps working). Opened as a draft for reference and to get CI builds on every platform, not meant to be merged.

Conclusion: not worth it for now. Performance is about on par with C zstd, but the binary gets ~30% bigger compressed, and C zstd is well proven and safe enough as used here, so swapping it out doesn't buy much.

Size (Linux aarch64, measured locally)

file gzipped
C zstd (main) 199KB 95KB
zrip 277KB 124KB (+30%)
zrip, its crates built at opt-level s 211KB 98.5KB (+3%), but 8-20% slower

zrip's decoder compiles to ~126KB of code vs ~58KB for C zstd, mostly a few heavily inlined functions.

Speed

Pure in-memory decoding is on par with C zstd. Extracting whole archives through the binary (best of 25 runs, ±10% noise): phpstan +0-12%, aws about equal, google/apiclient-services (many small files) +8-13% and 161MB peak memory vs 128MB, due to how the streaming decoder stages blocks.

Correctness

  • All library tests pass with the zrip binary, after small test adjustments for zrip's error messages.
  • zrip rejects a tiny frame declaring a 1GB window, which libzstd accepts only through its single-pass shortcut. That's arguably more consistent; the test now expects the rejection.
  • Extracting a corpus of 259 real package archives gives byte-identical trees (69,583 files).

Not done

The SBOM script, README, license files (zrip is MIT; keeping the zstd BSD notice would be prudent as parts are ported from C zstd) and the committed binaries are not updated, so the SBOM and binary comparison checks are expected to fail.

Experiment, not for merging as is: the SBOM script, README and license
files still describe the C decoder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant