Repository navigation
Description
#184 was three questions and shipped one of them. This is the other two, recorded before the closed
issue stops being read.
What #184 shipped (PR #409, 0c7d6ce)
Compressor.Compress now gates on compression.AlreadyCompressed, so the codec is not run over data
that arrived compressed. Measured on an M4 Max at zstd level 3: an 8 MiB zstd frame went 1.85ms → 2.2µs
and 33 MiB of allocation → zero; data that does compress pays 16ns.
That closes the defect the issue was filed about. It does not answer either of the following.
Step 2 — does an entropy gate earn its place, and at what threshold?
AlreadyCompressed recognizes formats by magic bytes only. It says nothing about the case the magic
bytes cannot see: CRAM, Parquet, ORC, HDF5 and Zarr compress per column or per chunk inside an
uncompressed container, so the container's first four bytes are readable and the payload behind them is
already at its entropy limit. Compress runs a full codec pass over those and then discards the result
via the len(compressed) >= len(data) fallback — correct output, wasted CPU, and these are exactly the
formats a research bucket is full of.
Analyze already computes Shannon entropy over the leading 4 KiB, so the number is available. It was
deliberately not used as a gate:
- High entropy is evidence, not proof. A gate on it declines to compress data that might have
compressed, which is a correctness-shaped decision made on a guess. Contrast the magic-byte gate,
where the format defines the answer. - No threshold has been measured in this repository. Picking 7.5 bits/byte because it appears in
other projects is the kind of unmeasured claim this tree has a documented history of (see the
throughput table that claimed 800–1200 MB/s no benchmark produced). - It is not free. The entropy pass is 2.13µs of
Analyze's 3.70µs againstAlreadyCompressed's
17ns. On a 64 KiB compressible write — 6.7µs of codec time — routing the gate throughAnalyzecost
+53.16% (p=0.002, benchstat, six runs). That regression is why the shipped gate is a separate
function. Any entropy gate has to buy more than it costs, and only for objects whose leading 4 KiB is
representative of the rest.
What would settle it: sample real CRAM/Parquet/HDF5 objects, measure the entropy of their leading 4 KiB
against the compression ratio zstd actually achieves on the whole object, and find whether a threshold
separates "will not compress" from "will" with few enough false positives to be worth 2.1µs. If no
threshold does, the answer is to say so and close this — a measured "no" is a result.
Note the sampling problem is real for these formats specifically: Parquet's leading bytes are PAR1
plus row-group data, HDF5's are a superblock. A 4 KiB prefix may be the least representative part of the
file.
Step 3 — do Selector, RuleSelector and AdaptiveSelector earn their place?
Still unreferenced outside internal/compression after #409:
Selector(selector.go:32) — the interfaceRuleSelector(selector.go:39) — extension/content-class rules to an algorithm and levelAdaptiveSelector(ml_selector.go:31) — the same, with per-key history
The write path takes its algorithm and level from config, one setting per mount, and #409 did not
change that. So there are three types deciding a question nobody asks them. Two directions:
- Wire
RuleSelector, so a mount'salgorithm: zstdbecomes a default that per-object rules can
override — lz4 for a file being appended to, a higher zstd level for cold-tier writes. That is a
user-visible feature and needs config surface, which is design work, not wiring. - Delete what is not wanted.
AdaptiveSelectoris the one to look at hardest: per-key history in
a write path that is per-mount by configuration, with the memory that implies, and no evidence any
deployment would benefit.pkg/apiand two other packages were deleted in this project on the same
reasoning.
Either is fine. What is not fine is three types staying in the tree with no caller and no decision,
which is the state #184 was filed about in the first place.
Step 4 — noted, not required
wasCompressed now carries four distinct reasons for false: compression disabled, below min_size,
already compressed, and the codec made it bigger. Callers only need the boolean today, so this is
recorded rather than filed — if a metric ever wants to distinguish "we skipped this" from "we tried and
it did not help", that is when the return type needs to change.
Where to look
internal/compression/analyzer.go—Analyze,AlreadyCompressed,classifyByMagic,shannonEntropyinternal/compression/s3_integration.go:126—Compress, the one caller of the gateinternal/compression/skip_compressed_bench_test.go—BenchmarkGateVersusAnalyzeis the 17ns-vs-3.8µs measurementdocs/features/compression.md— the two format lists, pinned byTestAlreadyCompressedMatchesTheDocumentedFormatLists
Activity
scttfrdmn commentedon Sep 17, 2026
Moved off the v0.15.0 milestone (renamed from v0.16.0) because 0.15.0 has been cut and this is not in it.
Worth noting what did ship in 0.15.0, since it changes the context slightly: seekable framing (#185) is now in the write and read paths, so
Compressininternal/compression/s3_integration.go— the one caller of the gate this issue is about — now also decides frame layout. The measurement this issue asks for is unaffected, but the decision about whether the three selectors have a caller should be made with the framing code in view rather than against the pre-#185 tree.