perf: comprehensive decompression and compression throughput optimizations - #140
Open
gheffern wants to merge 3 commits into
Open
perf: comprehensive decompression and compression throughput optimizations#140gheffern wants to merge 3 commits into
gheffern wants to merge 3 commits into
Conversation
- Replace quadratic nested scans in create_decode_tables with a single-pass histogram offset approach using stack-allocated count buffers. - Use branchless arithmetic in Block46 for bijective base-2 run-length calculation (es += (nextSym as u32 + 1) << logN). - Preserve 100% safe Rust in decompress.rs with #![forbid(unsafe_code)]. - Enhance differential assertion diagnostics in test-libbz2-rs-sys.
- Simplify bucket quadrant shift calculation in mainSort by using direct leading_zeros() on guaranteed positive sizes: (31 - bbSize.leading_zeros()) - 15. - Eliminate unnecessary Option matching and unwrap boilerplate while boosting compression throughput across all datasets (+15.8% Radar, +8.8% Silesia).
…oop peeling - Introduce 4-slice parallel CRC32 lookup table BZ2_CRC32TABLE_4 with a compact 4 KB memory footprint that fits entirely within CPU L1 Data Cache. - Implement BZ_UPDATE_CRC_4! macro supporting pre-broadcast constants for 4-byte unrolled processing. - Add compile-time inline loop peeling (write_two_bytes!, write_three_bytes!) in un_rle_obuf_to_output_fast to keep short runs (L=2, 3) inside the hot loop without branch exits or memset overhead. - Provides massive decompression throughput improvements on repetitive datasets (+105%+ speedup on radar data) while boosting Silesia text decompression to 53+ MB/s (+11.4% over main).
gheffern
force-pushed
the
feature/perf-optimizations
branch
from
August 15, 2026 16:01
2106f32 to
5f85fda
Compare
gheffern
marked this pull request as ready for review
August 15, 2026 16:10
Member
|
Can you provide a reproducible way of running the benchmarks? With our own benchmarks, I fail to see any change in performance with this PR. |
Author
|
I can do that. Give me just a day or two to get myself sorted out. I will make another repo with the benchmarking harness I used and the exact input files. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Comprehensive Decompression and Compression Throughput Optimizations
Summary
This PR improves decompression and compression performance across both repetitive/sparse data and high-entropy text/binary data without regressions.
Key improvements:
Benchmark Results
Benchmarks were executed across 20 iterations over 30 NEXRAD radar files (3.91 GB cumulative) and 11 Silesia corpus files (5.77 GB cumulative) under single-threaded execution.
main(f47b114)feature/perf-optimizations)Technical Details
The changes are organized into 3 focused commits:
1.
perf(huffman): optimize decode table construction and run-length math(23f190f)create_decode_tableswith a single-pass O(N) histogram offset builder using stack buffers.match nextSymbranch table inBlock46into branchless arithmetic:es += (nextSym as u32 + 1) << logN.#![forbid(unsafe_code)]indecompress.rs.2.
perf(compress): simplify bucket quadrant shift in mainSort(5c43870)mainSortusing direct leading zeros:(31 - bbSize.leading_zeros()) - 15.LZCNT/BSRinstruction, removing unnecessaryOptionmatching boilerplate.3.
perf(decompress): implement Slice-by-4 parallel CRC32 and short-run loop peeling(5f85fda)BZ2_CRC32TABLE_4, a net +3 KB static increase in.rodatafrom the original 1 KB table) that fits entirely in L1 Data Cache (12.5% of 32 KB L1D), avoiding cache conflict misses on high-entropy data.write_two_bytes!,write_three_bytes!) inun_rle_obuf_to_output_fast. Runs of length 1, 2, and 3 (representing verbatim symbols in the bzip2 specification) remain inside the hot inner loop without jumping tomemset/write_bytesor evaluating loop exit guards.Compatibility & Invariants
.rodatasize increase for the 4 KB CRC32 table; 0 additional heap allocations.#![forbid(unsafe_code)]preserved indecompress.rs. Zerounsafeadded to core algorithms.AI Assistance Disclosure
AI coding assistants (Google Antigravity with Gemini 3.7 Flash) were utilized to assist with exploring micro-architectural hypotheses, generating benchmark harnesses, and drafting documentation. All algorithmic designs, code changes, and performance verifications were reviewed, directed, and validated by human maintainers against the full test and differential suite.