Skip to content

Add LevelUltra and LevelUltraSIMD - #113

Merged
klauspost merged 10 commits into
minio:mainfrom
klauspost:ultra-level
Nov 23, 2026
Merged

klauspost merged 10 commits into
minio:mainfrom
klauspost:ultra-level

Conversation

@klauspost

@klauspost klauspost commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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 -ultra writes SIMD blocks, mz c -ultra -classic MinLZ 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.

Blocks Block Output size Compression MB/s Decompression MB/s
MinLZ 4KB -1.4% 21 → 17.3 (0.83x) 4,586 → 4,355 (0.95x)
MinLZ 16KB -2.7% 46 → 13.0 (0.28x) 4,984 → 4,931 (0.99x)
MinLZ 64KB -4.4% 74 → 10.8 (0.14x) 5,468 → 5,594 (1.02x)
MinLZ 256KB -6.4% 99 → 8.8 (0.09x) 4,967 → 4,984 (1.00x)
MinLZ 2MB -9.6% 139 → 7.2 (0.05x) 5,550 → 5,998 (1.08x)
MinLZ 8MB -10.9% 150 → 6.8 (0.05x) 5,910 → 6,624 (1.12x)
SIMD 4KB -3.7% 20 → 5.2 (0.27x) 3,305 → 2,108 (0.64x)
SIMD 16KB -4.2% 45 → 5.3 (0.12x) 4,863 → 3,893 (0.80x)
SIMD 64KB -4.3% 74 → 9.1 (0.12x) 8,232 → 7,438 (0.90x)
SIMD 256KB -6.8% 104 → 8.4 (0.08x) 10,209 → 9,724 (0.95x)
SIMD 2MB -11.2% 152 → 7.5 (0.05x) 11,694 → 11,938 (1.02x)
SIMD 8MB -13.4% 170 → 6.5 (0.04x) 11,529 → 12,123 (1.05x)

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:

Stream MinLZ Ultra MinLZ SIMD Ultra Compression MiB/s (MinLZ / SIMD)
JSON -6.7% -8.5% 115 / 110
CSV -9.5% -10.5% 52 / 47
Logs -10.9% -14.2% 64 / 77
Serialized -8.2% -7.4% 86 / 68
Backup -4.8% -3.6% 60 / 50

Memory for one 8MB block being compressed: about 90MB (LevelUltra) and 150MB (LevelUltraSIMD). mz c -ultra -cpu 4 peaked at 718MB (SIMD) and 502MB (-classic).

Design notes

  • Fallback to Smallest. LevelUltraSIMD also encodes each block with the parse of LevelSmallestSIMD and keeps the smaller, so its blocks are practically never larger. The fallback keeps the free tables of LevelUltraSIMD (below), whose size estimate can rarely pick a table that LevelSmallestSIMD would 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).
  • Small SIMD blocks (2-16KB) are parsed twice. On small blocks most streams are stored at 8 bits a value, which adaptive prices don't know. The first pass finds the streams that put will 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.
  • No 64 byte table threshold for LevelUltraSIMD. New tables cost only their size: -2% at 4KB, nothing at 2MB and up, at some decode speed on small blocks.
  • Operation budget. SIMD operations without literals never start with a repeat of fewer than 4 bytes, so an operation outputs at least 3 bytes on average and an 8MB block stays within 128 chunks.
  • Memory. The tree is sized from the largest offset and isn't cleared between blocks; only the hash heads are. 2^20 hash heads give the same output as 2^22 for 8MB blocks (within 0.001%) and are 2-5% faster.
  • isSIMDLevel replaces level >= LevelSuperFastSIMD, since level 8 is a MinLZ level.

Tests

  • Both levels are in the level loops and simdLevels, FuzzEncodingBlocks (inputs up to 256KB, 64KB with -short, not under -race) and FuzzDecodeSIMD seeds. TestEncodeAsmGolden pins LevelUltra output (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.
  • Ultra inputs are cut to 64KB in some -short SIMD tests. go test -short -race of the package goes from 125s to about 145s.

Checked with noasm, nounsafe, 386 and go fix. A 3-minute FuzzEncodingBlocks run found nothing.

Not in this PR

  • Delta literals: an experiment measured what delta-aware parsing plus operations that only set the reference offset could add. -0.3 to -0.9% on binary data (images, executables), -1 to -3% on msgpack, nothing on text, logs, JSON or records. Worth a follow-up, gated on blocks that already choose delta chunks.
  • Decompression of small SIMD ultra blocks could be traded back by a per-operation bias or the table threshold, if it matters.

Summary by CodeRabbit

  • New Features
    • Added Ultra and Ultra SIMD compression levels for higher-compression output.
    • Added the -ultra command-line option. SIMD is selected by default; use -classic for classic Ultra. The option cannot be combined with the SIMD delta option.
    • Added Ultra levels to stream and writer compression options.
  • Documentation
    • Updated usage guidance and benchmark results, including comparisons of Ultra compression ratio, speed, decompression, and memory use.

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).
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds classic Ultra (level 8) and Ultra SIMD (level 9) compression. New match-search and sequence-pricing paths encode blocks at these levels. The levels are available through the encoding APIs, writers, and CLI. The changes also update SIMD table-cost handling, tests, and documentation.

Changes: Ultra Compression

Layer / File(s) Summary
Level identifiers and dispatch
encode.go, minlz_test.go
Adds LevelUltra and LevelUltraSIMD, dispatches them through Encode and TryEncode, and identifies SIMD levels without classifying classic Ultra as SIMD.
Ultra parsing and output
encode_ultra.go
Adds binary-tree match search, classic and SIMD match pricing, sequence selection, output emission, and fallback encoding.
SIMD Ultra cost and encoder integration
encode-simd.go, encode_l3.go, encode-simd_asm_test.go
Adds the Ultra SIMD encoder path and fallback handling. Makes table-cost estimates configurable for Ultra SIMD.
Writer, CLI, and documentation
writer.go, writer_test.go, cmd/mz/compress.go, README.md, go.mod, _generate/go.mod
Accepts the levels in the writer and CLI. Maps Ultra to Ultra SIMD when classic output is disabled. Documents the levels, options, and benchmark measurements. Updates Go and dependency versions.
Encoder, stream, and decoder validation
encode_test.go, cmd/mz/stats_test.go, fuzz_test.go, internal/reference/stream_test.go, internal/reference/simd.go, decode-simd_test.go, minlz_test.go, asm_amd64.go, _generate/gen.go
Extends encoder, SIMD statistics, writer, stream, round-trip, and fuzz tests to cover Ultra levels. Adds SIMD table-change diagnostics after decode errors and clarifies emitter destination-capacity requirements.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Encode
  participant SIMDEncoder
  participant UltraParser
  Encode->>SIMDEncoder: Dispatch LevelUltraSIMD block
  SIMDEncoder->>UltraParser: Parse block and select sequences
  UltraParser-->>SIMDEncoder: Return selected sequences
  SIMDEncoder-->>Encode: Finish block and apply fallback
Loading

Suggested reviewers: lizthegrey

Merge Risk: Minimal · up to 72a1a

This adds two new opt-in Ultra compression levels with CLI and writer support. Earlier review findings were addressed or withdrawn, and no actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Add LevelUltra and LevelUltraSIMD" names the main change. The changeset adds the public constants LevelUltra (8) and LevelUltraSIMD (9), the encode_ultra.go parsers, the encoder dispatch, a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Add LevelUltra and LevelUltraSIMD" names the main change. The changeset adds the public constants LevelUltra (8) and LevelUltraSIMD (9), the encode_ultra.go parsers, the encoder dispatch, and the CLI -ultra flag. The title is short, specific, and matches the primary objective of PR #113.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit found a path through bytes,
And mapped the matches as it goes.
Classic hops and SIMD bounds,
Pick the sequences, emit the sounds.
The stream runs on; the burrow knows.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 082e7c09-2d5c-4472-98f7-2144edb7bf6a
Commits

Reviewing files that changed from the base of the PR and between 828ca21 and 72a1a67.

Files ignored due to path filters: 8

  • _generate/go.sum is excluded by !**/*.sum
  • go.sum is excluded by !**/*.sum
  • img/10gb-v1-comp.png is excluded by !**/*.png
  • img/csv-v1-comp.png is excluded by !**/*.png
  • img/json-v1-comp.png is excluded by !**/*.png
  • img/json-v1-decomp.png is excluded by !**/*.png
  • img/logs-v1-comp.png is excluded by !**/*.png
  • img/msgp-v1-comp.png is excluded by !**/*.png
Files selected for processing: 1

  • _generate/go.mod

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

coderabbitai[bot]

This comment was marked as resolved.

* 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.
@klauspost

Copy link
Copy Markdown
Collaborator Author

Review feedback addressed

Commit bf3b328 handles the 5 CodeRabbit findings. 4 are fixed and 1 is declined with a doc change. The reasons are in each thread.

Files changed: encode_ultra.go, encode.go, README.md

  • Fixed: the SIMD statistics rescale now triggers on committed input. It is size neutral.
  • Fixed: the parser pool no longer keeps the input alive.
  • Fixed: two README corrections, the MinLZ block reach and the Writer blocks in flight.
  • Declined: the fallback keeps LevelUltraSIMD's free tables. Its docs now say "practically never larger" than LevelSmallestSIMD.

Commit d4b7cbd adds Ultra rows and redrawn charts to the README stream benchmarks.

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".
@klauspost
klauspost merged commit 2be21a7 into minio:main Nov 23, 2026
69 checks passed
@klauspost
klauspost deleted the ultra-level branch November 23, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant