Repository navigation
Conversation
Byron
force-pushed
the
fdeflate-backend
branch
from
October 17, 2026 03:36
b1dd377 to
7a9e1eb
Compare
The previous writer-to-Vec bridge capped input per call but could still retain unbounded parser data and encoded output. Its decoder stopped at internal scratch boundaries, so a sufficiently sized caller buffer could still receive an incomplete result. Error paths also lost consumed/produced accounting. Drive StreamingCompressor directly and map its progress to flate2 counters and statuses. Drain/decode repeatedly across the reusable 96 KiB scratch buffer, decode directly into large initialized destinations when history permits, and copy only initialized output into MaybeUninit destinations. Preserve terminal errors and trailing input, allow zero-output calls to finish empty streams and checksums, and reuse allocations on reset. Forbid unsafe code in this adapter. Add regressions for exact output sizes, one-call Finish, slice/Vec transitions, history across chunks, checksum errors, and trailing bytes. Re-enable existing flush byte-layout tests, and gate backend-specific tests on actual selection. The new APIs require the accompanying fdeflate series ending at c99a7578a082ba526252559b04e49fb4e58f7092. Keep a local Cargo patch while those commits are unpublished; the dependency branch must contain them before that override is removed. Document this setup and the std/Rust 1.88 requirement. no_std support remains deferred. Validation: the complete fdeflate-backend cargo test suite passed on an isolated export of this staged adapter, before the separate shared-writer changes.
A codec can have pending output when Write::flush requests Sync. In particular, miniz may return a short buffer after draining old bytes without processing that new flush request, leaving accepted input invisible to a decoder. Issuing the flush into an already occupied output buffer also obscured completion. Drain existing codec output before requesting Sync with a fresh buffer, and repeat if the result fills that buffer. Respect StreamEnd and flush the wrapped writer after all encoded bytes have been delivered. Track a cursor into pending writer output instead of repeatedly draining the front of its Vec. This avoids moving the remaining bytes after every short write, retries Interrupted, and preserves progress across a WouldBlock error. Reset the cursor when the buffer is drained or the writer is replaced. Add regressions proving that flushing makes every input byte decodable across levels and boundary sizes, and that a retry after partial writes, Interrupted, and WouldBlock preserves the stream. Validation on an isolated staged tree: the full default/miniz suite passed; all six streaming tests also passed with fdeflate, fdeflate+zlib-rs, and fdeflate+zlib (exercising backend precedence as well as the shared writer).
The buffering changes need coverage beyond successful one-shot round trips: flush schedules, zero-sized destinations, unfinished resets, malformed input, and truncation can expose counter, history, and progress bugs. Share one exercise harness between a deterministic size/pattern/level matrix and a libFuzzer target. Compare encoded streams and successful decodes with miniz_oxide, bound decoding work on malformed inputs, and check consumption, output limits, and forward progress through changing chunk sizes and flushes. Reset both codecs after partial work or an error before testing fresh streams. Gate the malformed-input and unfinished-reset matrix on fdeflate actually being selected: other backends have independent differences in those cases. Add the independent decoder as a dev/fuzz dependency, expose the fdeflate fuzz feature, and repeat the local dependency patch in the fuzz workspace. Validation on an isolated staged tree: the deterministic matrix passed and cargo check built the streaming fuzz target with the fdeflate feature. Earlier implementation validation also completed a 30-second nightly libFuzzer run (2,481 executions) without a failure. The regular streaming contract tests remain enabled for every backend.
Inflate's Debug implementation only reported byte counters, hiding the buffered-output positions and terminal state needed to diagnose streaming behavior. Include drain_pos, decode_pos, done, and error alongside total_in and total_out. Keep inner and scratch omitted so diagnostics do not dump the decoder internals or buffer contents. This changes diagnostic output only. Validation: cargo check --no-default-features --features fdeflate --offline, cargo fmt --all -- --check, and git diff --check passed.
A bounded token buffer can describe several MiB of repeated input before it must emit a DEFLATE block. The adapter test previously supplied 2 MiB and assumed that one byte of output space must stop input consumption, which is no longer true when the input fits in pending match tokens. Use 8 MiB of repeated input so the test crosses the token limit. Retain the assertions for partial consumption, output progress and decoding of the finished stream. This tests backpressure without imposing the old 128 KiB Huffman block boundary on the backend. Validation: cargo test --offline --release --no-default-features --features fdeflate passed the unit, integration and documentation tests with the token-budget implementation and without the RLE optimization.
The streaming microbenchmarks emphasize random or highly repetitive inputs and do not expose all costs of retaining tokens across batches. Add a compression-only corpus harness for local Rust-source and executable snapshots, plus deterministic low-alphabet and skewed byte distributions. Measure levels 1, 4, 6 and 9 with a zlib wrapper and 32 KiB output slices. Reuse the compressor and output allocation, include reset costs, warm up each case, and report the median of five samples lasting at least 50 ms. Emit elapsed time and compressed size as CSV so throughput improvements can be considered alongside ratio changes. Source/executable snapshots are supplied by the caller and are not checked into the repository. Validation: the harness was run across all four workloads and levels in the before/after token-budget comparison. It also compiles in the passing fdeflate-backend release test suite; formatting checks passed.
Shnatsel
force-pushed
the
fdeflate-backend
branch
from
October 17, 2026 18:32
f7d3aa1 to
112b3ac
Compare
Member
|
Once #589 has added their benchmarks, it might be worth adapting them to run here as well. |
Contributor
|
Rebased this as best as I could (on the patched version of fdeflate) and ran the #589 benchmarks to compare. Large files, MB/s of uncompressed data (higher is better), compressed size in MB:
Small streams, ns per stream (lower is better), with one
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for using fdeflate as a compression/decompression backend. It's already proven in the
pngcrate used by Chromium (among other things).The backend priority is above miniz_oxide but below zlib and zlib-rs.
This PR is basically #545 but with more effort put into it.
It still depends on two upstream PRs, so I'm marking this a draft:
Buffer sizes are a guess for now, and will need tuning. Larger sizes will likely improve performance by reducing the frequency of copying the lookback buffer, at the cost of higher memory use. These will need to be adjusted to be in line with the other backends for the total amount of memory consumed.
@fintelia FYI