Skip to content

Accelerate RAR 2.0 Huffman and bit decoding - #102

Merged
bitplane merged 1 commit into
masterfrom
perf/rar20-huffman-bit-reading
Oct 25, 2026
Merged

bitplane merged 1 commit into
masterfrom
perf/rar20-huffman-bit-reading

Conversation

@bitplane

Copy link
Copy Markdown
Owner

RAR 2.0 decoded every Huffman symbol and multi-bit field one bit at a time. Reuse the shared 10-bit canonical lookup for the main LZ alphabet and read multi-bit fields a byte at a time, preserving the original results, diagnostics, and bit consumption on errors.

Keep level, distance, length, and audio tables bitwise: their setup cost and frequent one-bit audio codes do not benefit reliably from a lookup. A compile-time mode keeps that choice explicit without adding runtime state. Quota-limited readers retain their symbol-only table allocations and allocation-refusal behavior. Unlimited readers add one 4 KiB main lookup, also copied by checkpoints.

Add exhaustive comparisons with the original bitwise logic for both decoding modes and budget policies, including input tails, errors, clones, and compaction. Add cargo bench -p rars --bench rar20_decode with eight generated, round-trip-checked fixtures; fresh decoders deliberately include table setup.

Measured in three alternating runs against master using public decoder calls:

  • 256 KiB short-match and literal fixtures: about 2× and 2.5× faster.
  • Repetitive fixtures: about 11–28% less decoding time; 128-byte members: about 20% less.
  • Smooth and noisy audio: within a few percent of baseline; RAR29/RAR5 controls show no substantial regression.
  • Tradeoff: one-byte members take about 2.9 µs instead of 2.5 µs (about 16% slower) due to lookup setup. These synthetic codec results are not general archive-extraction speedups.

Validation:

  • Release package tests, including integration and doc tests: 2,610 passed; 17 existing ignored. Minimal-feature library tests: 352 passed.
  • Formatting and all-target Clippy with warnings denied, with default and minimal features.
  • The committed Criterion benchmark completed successfully.
  • Independent claude -p plan, refinement, and final reviews: approved, no blocking findings.

@bitplane
bitplane merged commit e4266bd into master Oct 25, 2026
24 checks passed
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