Repository navigation
Fix stream latency and reduce codec allocations with measured performance improvements - #13
Merged
cinderblocks merged 28 commits intoNov 3, 2026
Conversation
…ecks and diagnostics
…ler golden outputs
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.
ZInputStream could refill compressed input while decoded output remained buffered, and ZOutputStream.Flush did not expose pending compressed messages. This PR fixes those behaviors, releases retained caller/source buffers, and reduces codec allocation and reset overhead. The follow-up performance review adds measured encoder improvements and an opt-in smaller compressor.
Stream correctness and reuse
Additional performance changes
Each change has a focused commit and regression coverage or an existing regression suite covering the affected behavior:
The prior Ubuntu allocation test failure was fixed by warming additional calls and comparing three measurement batches. Recurring per-message allocations still fail the test; one-time runtime initialization does not count as codec scratch.
Measurements and rejected experiments
The additional experiment report contains all 54 cases, three baseline/final runs, allocation counts, compressed sizes/hashes, raw data, a later baseline control, and reproducible rejected patches. These compare against the previous PR head bf13e1d. The earlier report separately compares the initial changes against v2.0.2; percentages are not cumulative.
Windows ARM64, .NET 8.0.28, Release, memory-backed I/O:
Large-data CPU results are mixed. The full-suite low-level level-0 cases measured about 11-12% slower, while isolated level-0 processes reverse that result. A subsequent baseline control also showed significant host variability. The report includes these results and small regressions; it does not claim universal CPU gains. Allocation counts, buffer-size reductions and the reviewed compressed-size change are more robust conclusions.
Stackalloc for all small Huffman scratch, stackalloc for only the value workspace, direct stored-block output, and an array copy/checksum specialization were prototyped and rejected because timing did not justify retaining them. Full raw/wrapped engine duplication and wrapper-buffer rental were analyzed without adopting them; the wrapper's protected arrays complicate safe shared ownership. Flush batching is measured as a caller-controlled latency/size tradeoff; explicit Flush still exposes each message immediately.
Warm allocation savings do not equal lower peak resident memory: caches retain cleared arrays, and cold or highly concurrent streams can allocate full buffers. Explicit Reset retains its codec until disposal and requires callers to frame independent messages. The package version is unchanged; no release or publication is included.
Validation
9aa46af; GitHub reports the PR merge state as clean. No sustained fuzz campaign or x64 benchmark was run locally.