Expand description
Compression codecs. v0.1 ships store, zstd, zstd-with-dictionary and xz (LZMA2); the codec id space is reserved for context mixing, model-predictive, delta and float-split codecs (spec §4.2).
Structs§
- Codec
Options - Decision
- What a sample decided for a block (
decide_on_sample). - Encoded
- Encoded output plus the parameters the decoder needs.
Enums§
- Codec
Choice - Which codecs the packer may try for a block.
Constants§
- EFFORT_
DEFAULT - Default
effort: the full trial. - FILTER_
ARM64 - FILTER_
NONE - FILTER_
X86 - PPMD
- SAMPLE_
SLICE - Length of one slice of the codec-choice sample (§2.1 of
docs/design/plans/1.1-codec-sampling.md). - STORE
- XZ
- ZSTD
- ZSTD_
DELTA - zstd with a raw-content dictionary made of chunks of an earlier version (
BlobRecord.d). - ZSTD_
DICT
Functions§
- arm64_
alignment - Heuristic: ARM64 code is a stream of 4-byte instructions with frequent
BLcalls to near targets (imm26 sign-extended, magnitude below 2^20 words). Random words qualify 0.05 % of the time; real code 1–5 %. Blocks start at arbitrary chunk boundaries, so all four word alignments are tried; returns the byte offset of the first aligned instruction word. - arm64_
convert - ARM64 branch converter (the
arm64BCJ filter from XZ Utils, 0BSD): converts the immediate ofBLandADRPinstructions from PC-relative to absolute form. Symmetric, works on 4-byte words. - compress_
best - Try every applicable codec (with and without a branch filter when the block looks like x86 or ARM64 machine code) and keep the smallest output; store if nothing is smaller. Blocks that zstd cannot shrink by at least 3 % are treated as incompressible and the slower codecs are skipped.
- decide_
on_ sample - Decide filter and codec for a block on its sample (
sample()of the block; efforts 2..=4). The same heuristics and codecs as the full trial run on the sample, in the same order, and the candidate the full trial would have kept on the sample wins.looks_like_textis judged on the (filtered) sample here, not on the first 64 KiB of the block as in the full trial: a strided sample represents a mixed block better; this is intended. - decompress
- decompress_
with - filter_
id - Filter byte layout: low nibble = filter id, high nibble = filter parameter (ARM64: byte offset of the first aligned instruction word, 0..3).
- filter_
param - looks_
like_ text - Heuristic: does the block look like text (worth a PPMd attempt)? Samples up to 64 KiB.
- looks_
like_ x86 - Heuristic: x86/x64 machine code has many
E8/E9CALL/JMP opcodes whose rel32 operand has a most-significant byte of00orFF(near targets). Random bytes hit that pattern about 0.006 % of the time; real code sections hit it 0.5–2 % of the time. - name
- ppmd_
params - PPMd model order / memory chosen deterministically from the block size: memory grows with the block (16 MiB..256 MiB), order 16 is a good text default for PPMd H.
- sample
- The codec-choice sample of a block: the block itself (borrowed) when it is small enough for the full trial, otherwise the concatenation of its sample slices. A pure function of the bytes.
- sample_
full_ trial_ max - Largest block that is never sampled:
2 * slices * SAMPLE_SLICE(128 KiB for blocks up to 1 MiB), below which a sampled trial costs about as much as the full one. Every golden archive holds one blob below this size, so efforts 2..=5 reproduce them by construction. - sample_
offsets - Byte offsets of the sample slices of a block of
lenbytes, evenly spaced from 0 tolen - SAMPLE_SLICE, each rounded down to a multiple of 4 so that the word alignmentarm64_alignmentfinds on the sample is the block’s. Empty when the block is not sampled. - sample_
slices - Number of slices the sample of a block of
lenbytes has: one per 128 KiB, at least 8 (a 1 MiB block gives 8 slices = 64 KiB) and at most 32 (256 KiB at 4 MiB and above). A block prefix must not be used instead: blocks concatenate chunks of several files and a prefix predicts the wrong codec on a third of the benchmark blocks (measured, see the plan). - samples_
block - Does
compress_bestdecide the codec of a block oflenbytes on a sample with these options? (Bestat efforts 2..=4 and a block abovesample_full_trial_max.) - train_
dict - Train a zstd dictionary on the unique chunks (needs at least 8 samples).
- x86_
convert - x86 BCJ branch converter (the classic LZMA SDK
x86.ctransform, public domain): rewrites the relative targets ofE8/E9CALL/JMP instructions into absolute addresses so that repeated calls to the same function become identical byte sequences. Symmetric:encoding = falserestores the original bytes exactly. Returns the number of bytes fully processed. - zstd_
compress_ with_ prefix - zstd with
prefixas a raw-content dictionary (the “patch-from” model): matches may reach into the prefix, so a new version of a document costs about the size of its edits. - zstd_
decompress_ with_ prefix