Repository navigation
Add LevelUltra and LevelUltraSIMD - #113
Conversation
Two new levels that parse like zstd's btultra2 (zstd -19): a binary tree finds the matches at each position, and a forward dynamic program over segments of up to 4096 bytes picks the cheapest path. * LevelUltra (8) writes MinLZ blocks, priced with exact byte costs. * LevelUltraSIMD (9) writes SIMD blocks, priced with adaptive statistics of the SIMD streams (tokens, literal lengths, offset symbols, escapes, literals), rescaled every 256 KiB. * mz c -ultra, with -classic for LevelUltra. Single core, geomean of 10 files against Smallest of the same block type: 8MB blocks -10.9% (MinLZ) and -13.4% (SIMD), 2MB -9.6% / -11.2%, 64KB -4.4% / -4.3%, 4KB -1.4% / -3.7%. Compression runs at 5-17 MB/s, up to 25x slower than Smallest. Decompression is as fast as Smallest's on blocks of 256KB and more. LevelUltraSIMD also encodes each block with LevelSmallestSIMD and keeps the smaller one. On low-entropy data such as hex, DNA or 2-bit symbols the adaptive prices settle on many short matches that are each cheaper than their literals at the prices they make, while fewer matches cost less in total. Its blocks are never larger than LevelSmallestSIMD's. SIMD blocks of 2-16KB are parsed twice: the first pass finds the streams that will be stored at 8 bits a value, as on small blocks, and seeds the statistics of the second. LevelUltraSIMD prices new tables at their size, without the 64 byte threshold that trades size for decode speed. Memory for one 8MB block is about 90MB (LevelUltra) and 150MB (LevelUltraSIMD).
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
* Rescale the SIMD statistics when the committed input passes a 256 KiB boundary. The check used the segment start, which positions without matches move ahead of the committed input. Size neutral (+-0.1%). * Don't keep the input alive in the parser pool. * The fallback keeps LevelUltraSIMD's free tables, so its blocks are practically, not strictly, never larger than LevelSmallestSIMD's. Say so. * README: MinLZ blocks reach back about 2MB, and a Writer compresses up to one block more than its concurrency.
MinLZ Ultra and MinLZ SIMD Ultra rows in the STREAMS tables, measured with gocomp (16 threads, 4MB blocks, single-threaded decompression, 3 passes), and the charts redrawn from the tables. The rows were measured with threads pinned to cores, unlike the older rows, which the setup notes say.
Review feedback addressedCommit Files changed:
Commit |
Measured per file, LevelUltra is 7-75 times slower than LevelSmallest on 8MB blocks (about 20 on the geometric mean, most on logs and formatted JSON), so "up to 20/25 times slower" was wrong. The size gains are averages too.
The amd64 emitters store 3-byte lengths with 4 bytes, one byte past the operation. A copy with 4 literals and a long repeat is 11 bytes, which fills TestEmitters' 11-byte tmp. tmp is on the heap, and with -race every object below 16 bytes has a 16-byte slot to itself, at its end, so the byte went into the next object. In CI that was a class of the reference decoder, which then rejected level 5 blocks that the decoders accepted. The emitter contracts now say dst needs room for that byte. When the reference decoder rejects a block, its error now names any class, or any table the encoders and decoders share, that changed since init.
The generator replaces minlz with ../, so the root bump left _generate/go.mod stale. avo's runtime load of internal/pivco/kernel then failed with "updates to go.mod needed", surfacing as panic: unknown variable "p".
Adds two compression levels that parse like zstd's btultra2 (
zstd -19): a binary tree finds the matches at each position, and a forward dynamic program over segments of up to 4096 bytes picks the cheapest combination of matches and literals.LevelUltra(8) writes MinLZ blocks. Costs are exact byte counts.LevelUltraSIMD(9) writes SIMD blocks. Costs come from adaptive statistics of the SIMD streams (tokens, literal lengths, offset symbols, escapes, literals), rescaled every 256 KiB.mz c -ultrawrites SIMD blocks,mz c -ultra -classicMinLZ blocks.Results
Single core, AMD Ryzen 9 9950X, geometric mean of 10 files (logs, JSON, CSV, text, a tar file, protobuf, URLs), against Smallest of the same block type. Also in the README.
At 8MB blocks the largest gains are on logs and JSON (cockroach log -24%, formatted JSON -24%, apache log -23% vs
LevelSmallestSIMD). The worst case found is 2-bit random data, at 2.6 MB/s.The README STREAMS tables have Ultra rows (gocomp, 16 threads, 4MB blocks, single-threaded decompression). Size against level 3 of the same block type:
Memory for one 8MB block being compressed: about 90MB (
LevelUltra) and 150MB (LevelUltraSIMD).mz c -ultra -cpu 4peaked at 718MB (SIMD) and 502MB (-classic).Design notes
LevelUltraSIMDalso encodes each block with the parse ofLevelSmallestSIMDand keeps the smaller, so its blocks are practically never larger. The fallback keeps the free tables ofLevelUltraSIMD(below), whose size estimate can rarely pick a table thatLevelSmallestSIMDwould not, so it isn't a strict bound.On low-entropy data (hex of random bytes, DNA, 2-bit symbols) the adaptive prices settle on many short matches. At the prices those matches make, each is cheaper than its literals, but fewer matches cost less in total: without the fallback, ultra was 2-10% larger than Smallest there. The prices were checked against the bits actually written and are accurate, so this is a choice between two self-consistent statistics, which price changes didn't fix.
The fallback costs about 3% of the time on large blocks, more on small ones (Smallest clears 10MB of tables per block).
putwill store, using the encoder's own rule, and seeds the statistics of the second pass (as zstd's first block). -0.3 to -0.4% at 4-16KB. Blocks up to 2KB price every stream as stored.LevelUltraSIMD. New tables cost only their size: -2% at 4KB, nothing at 2MB and up, at some decode speed on small blocks.isSIMDLevelreplaceslevel >= LevelSuperFastSIMD, since level 8 is a MinLZ level.Tests
simdLevels,FuzzEncodingBlocks(inputs up to 256KB, 64KB with-short, not under-race) andFuzzDecodeSIMDseeds.TestEncodeAsmGoldenpinsLevelUltraoutput (inputs up to 64KB with-race).TestUltraClassicPrices: every MinLZ operation is emitted in the size it was priced at, over the offset classes, lengths and fused literal counts.TestUltraOffsets: matches at offsets 63/64, 1024/1025, 65599/65600 and the largest copy3 offset (and one past it).TestUltraSIMDOps: no repeat of fewer than 4 bytes without literals (fails on an earlier version that allowed it), and an 8MB block with an operation every 3 bytes fits.TestUltraStreamCounts: the SIMD statistics count exactly the values the emitters write to each stream.-shortSIMD tests.go test -short -raceof the package goes from 125s to about 145s.Checked with
noasm,nounsafe, 386 andgo fix. A 3-minuteFuzzEncodingBlocksrun found nothing.Not in this PR
Summary by CodeRabbit
-ultracommand-line option. SIMD is selected by default; use-classicfor classic Ultra. The option cannot be combined with the SIMD delta option.