Repository navigation
image: decode zstd layers with zrip - #356
Conversation
Zstd layers decode with zrip 0.8.25 instead of ruzstd. zrip's FrameDecoder reads every frame of a stream and skips skippable frames, so it replaces the ZstdReader wrapper that zstd:chunked layers needed. The tests write their frames with zrip as well. A 292 MB rootfs layer at zstd level 3 decodes in 300 ms instead of 961 ms, and pulling its OCI layout takes 1.92 s instead of 2.58 s.
zrip 0.8.26 is the current release. It changes only levels 3 and 4 of the encoder and adds an option to drop the content checksum; layer decoding is unchanged.
congwang-mk
left a comment
There was a problem hiding this comment.
Thanks for the PR and for the careful benchmark writeup. The swap itself looks correct to me (multi-frame, skippable frames, truncation and digest verification all still behave). A few comments inline.
| cow = ["dep:walkdir", "dep:pathdiff", "dep:ring"] | ||
| profiles = ["dep:toml"] | ||
| image = ["cow", "dep:uuid", "dep:tar", "dep:flate2", "dep:ruzstd", "dep:base64", "dep:bollard", "dep:futures-util"] | ||
| image = ["cow", "dep:uuid", "dep:tar", "dep:flate2", "dep:zrip", "dep:base64", "dep:bollard", "dep:futures-util"] |
There was a problem hiding this comment.
The dependency guard in .github/workflows/ci.yml (lines 81-86) still forbids ruzstd for the non-image feature sets. Please replace it with zrip there, otherwise nothing catches the zstd decoder leaking into those builds.
| tar = { version = "0.4", optional = true } | ||
| flate2 = { version = "1", default-features = false, features = ["rust_backend"], optional = true } | ||
| ruzstd = { version = "0.9", optional = true } | ||
| zrip = { version = "0.8.26", optional = true } |
There was a problem hiding this comment.
My main hesitation is maturity: this path parses untrusted image layers, and zrip is about five months old with 46 releases (0.8.25 fixed a decoder over-reservation the day before this pin). We also do not verify diff_ids, so a wrong decode of a frame without a content checksum would go unnoticed. Is the decoder fuzzed differentially against reference zstd?
|
|
||
| [[package]] | ||
| name = "fearless_simd" | ||
| version = "1.2.0" |
There was a problem hiding this comment.
Note that the default simd feature brings in fearless_simd, which does contain unsafe, so the tree is not unsafe-free. How much decode speed is lost with default-features = false, features = ["std", "frame"]?
sandlock-core takes zrip with only its std and frame features. The default simd feature brings fearless_simd, which holds the unsafe target-feature calls, and ldm only serves the encoder. Without the dispatch, a 292 MB zstd -3 layer decodes in 358 ms instead of 276 ms (ruzstd: 978 ms), and pulling it takes 1.96 s instead of 1.88 s. Applications can still enable zrip's simd feature themselves. The CI dependency check forbids zrip instead of ruzstd in the feature sets without image.
|
Thanks for the review and the merge! Answers to your questions, for the record:
|
zrip0.8.26 instead ofruzstd0.9.zrip::FrameDecoderreads every frame of a stream and skips skippable frames, so it replaces theZstdReaderwrapper that zstd:chunked layers needed (about 60 lines).zripis pure Rust,#![forbid(unsafe_code)]in all its crates, MIT. I maintain it.zripbuilds withstdandframeonly. Its defaultsimdfeature dispatches to AVX2 code at runtime throughfearless_simd, which usesunsafe; without it, layers decode about 30% slower than with it. An application that depends onzripwithsimdgets it back.zrip::compressat level 1 instead ofruzstd'sFastest; they still put a skippable frame between data frames.ruzstdandtwox-hashleaveCargo.lock, and the CI dependency check forbidszripwhere it forbaderuzstd.A 292 MB rootfs layer (15,188 entries: Python stdlib, docs, zoneinfo, locales,
/usr/sbin) compressed withzstd -3, in an OCI layout. Pull:image::pull("oci:<dir>")into a fresh cache on tmpfs, so it verifies the blob, decodes it and unpacks the rootfs. Decode: the layer alone toio::sinkwith each decoder. One pinned CPU (i7-8700B, KVM), median of 5 processes (3 for the uncompressed layer), each the best of 5 rounds.main(ruzstd)zrip)