Allow later nonempty files in one compression invocation
perfloop-oss/lz4 · Uncatalogued performance
https://perfloop.ai/t/oss/case_475rpz6t92
Verdict
VERIFIED · settled 2026-11-20 · merged as pierrec/lz4#299
What happened: The check fails before this change and passes with it.
Hypothesis
Named-file compression fails when a nonempty input follows a completed file. The command has already completed the previous output but cannot begin the next one. This breaks the documented list-of-files operation; no throughput benefit or real batch frequency has been measured.
At revision 8bbd9778866f036e932a403b46c656ed75cebbfd, Compress creates and configures one encoder at cmd/lz4c/compress.go:75-84. Each normal iteration closes it at lines 175-180. For a later input whose size is positive, lines 150-157 apply a new progress callback before Reset is reached at line 168. The resolved dependency is github.com/pierrec/lz4/v4 v4.1.33 from cmd/lz4c/go.mod, with no active local replacement. Its Writer.Apply accepts the new state, not the closed state; Writer.Reset restores that state. The source-derived trigger is a positive-size later input after a completed normal iteration, not every multi-file or benchmark invocation.
Receipt call_xv51wKOQfYqKZhWAlKTGGjxZ, output:1, runs `go test -count=1 -run '^TestHuntCompressTwoNonemptyFiles$' .` in cmd/lz4c. The test uses the real codec, two small nonempty regular inputs, -c=1, and -size=64K. It requires two successful files and independent output round trips. It fails before the second output with `two nonempty named files: got n=0 err=lz4: cannot apply options on closed or in error object, want n=2 err=<nil>`. Exit status 1 is the intended batch-success assertion failure, not a build failure. The fixture and additions to the existing compression test file are provisional proof methods.
The Case proof target is correct reset, option application, and finalization across the documented named-file loop, with each output decoding to its own input. The smallest next check is to make the exact two-file assertion pass through a local lifecycle-ordering correction. Mixed empty/nonempty inputs are a useful additional control because empty inputs bypass the per-file Apply branch. This repair need not change the codec's Apply contract or introduce a new public API.
The actual patch in https://github.com/pierrec/lz4/pull/293 permits ReadFrom on an active writer and flushes buffered prefixes. It neither permits Apply on a closed writer nor changes this CLI ordering, so this remains distinct from that active upstream work. The merged https://github.com/pierrec/lz4/pull/297 changes output acquisition and alias protection, not this ordering; preserve its replacement and failure-output semantics. README.md:20-43 documents the named-file list and README.md:76-81 names GitHub issues and pull requests as the contribution venue. No separate review archive was identified, and older local file history remains unavailable beyond the output-safety merge.
Change to test: Put the encoder into a reset state before applying each input's options while retaining the configured compression settings. Preserve one finalized frame per output and the documented ability to compress a list of named files.
Where it lives
Evidence
The check fails before this change and passes with it: `With -c=1, -size=64K and -bc, lz4c compress succeeds on two distinct named files when the first is empty or nonempty and the second is nonempty, finalizes outputs that each decompress byte-for-byte to its own input, and gives the second output the same frame descriptor as a single-file invocation with the same options.`
Checks: 2 of 2 passed. Verification: no defect found.