perf: optimize repeated SIMD workloads - #80
Open
geeknoid wants to merge 1 commit into
Open
Conversation
- Decode paired Base32 vectors with one validity reduction for cache-sized inputs. - Compact forgiving Base64 whitespace with SIMD shuffles and clean-block copies. - Keep Base64 parallel encoding serial below the measured 64 KiB cutoff. - Validate long ASCII inputs with AVX2 while preserving the existing short path. - Bound generic ASCII validity reductions so invalid data exits earlier. - Unroll byte swapping across four vectors to expose independent work. - Amortize growth in Base32, Base64, and hex append operations. The append APIs previously used `reserve_exact`, which requested only enough capacity for the current chunk and could therefore reallocate and copy the accumulated output on nearly every call. Using `reserve` permits geometric over-allocation, trading bounded spare capacity for amortized growth and drastically fewer reallocations, while one-shot encode and decode APIs continue allocating their known final sizes exactly. Representative native/static ABBA results from simd-benches: | Benchmark | Before | After | Delta | |---|---:|---:|---:| | Base32 decode, 1.6 KiB | 10.915 GiB/s | 13.088 GiB/s | +19.9% | | Base32 append encode, 10k chunks | 1.005 GiB/s | 1.747 GiB/s | +73.9% | | Base64 append encode, 10k chunks | 1.208 GiB/s | 2.688 GiB/s | +122.6% | | Hex append decode, 10k chunks | 3.861 GiB/s | 12.890 GiB/s | +233.8% | | Base64 forgiving MIME, 5.6 KiB | 0.939 GiB/s | 6.590 GiB/s | +602.0% | | ASCII validation, 4 KiB | 68.019 GiB/s | 82.592 GiB/s | +21.4% | | UTF-16 byte swap, 512 B | 50.130 GiB/s | 57.028 GiB/s | +13.8% | | UTF-32 byte swap, 128 KiB | 33.126 GiB/s | 40.803 GiB/s | +23.2% | | Base64 parallel, 4 threads, 16 KiB | 0.266 GiB/s | 6.995 GiB/s | +2531.6% |
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.
The append APIs previously used
reserve_exact, which requested only enough capacity for the current chunk and could therefore reallocate and copy the accumulated output on nearly every call. Usingreservepermits geometric over-allocation, trading bounded spare capacity for amortized growth and drastically fewer reallocations, while one-shot encode and decode APIs continue allocating their known final sizes exactly.Representative native/static ABBA results from simd-benches: