Repository navigation
perf(base32): optimize bulk scalar quanta - #17
Merged
Merged
Conversation
tisonkun
approved these changes
Nov 18, 2026
tisonkun
left a comment
Contributor
There was a problem hiding this comment.
Thanks for your contribution @cijiugechu! LGTM.
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.
Summary
Optimize Base32 scalar encoding and decoding with fixed-size chunks for inputs of at least 32 complete quanta, inspired by Sergey Davidoff’s How to avoid bounds checks in Rust (without unsafe!).
Scalar benchmark medians versus
1b226ab, seven alternating before/after runs with Base32 dispatch forced to scalar:Linked AArch64 benchmark assembly (rustc 1.94.0): hot-loop instructions drop from 41 → 32 for encoding and 59 → 42 for decoding; per-quantum bounds-check branches drop from 2 → 0 in both loops. Compiler Explorer: rustc 1.99.0, standalone before/after scalar assembly.
Tested on Apple M4, macOS 15.7.5 (
aarch64-apple-darwin), rustc 1.94.0 / LLVM 21.1.8, release with thin LTO and one codegen unit.cargo x testpasses with normal and forced-scalar dispatch (621 test executions each);cargo x checkpasses for native andx86_64-apple-darwintargets.