Skip to content

perf(base32): optimize bulk scalar quanta - #17

Merged
tisonkun merged 1 commit into
fast:mainfrom
cijiugechu:perf/base32-scalar-bounds
Nov 18, 2026
Merged

tisonkun merged 1 commit into
fast:mainfrom
cijiugechu:perf/base32-scalar-bounds

Conversation

@cijiugechu

@cijiugechu cijiugechu commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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:

Raw input Iterations Encode time (ms) Decode time (ms)
1 KiB 1,800,000 481 → 436 (−9.4%) 670 → 530 (−20.9%)
16 KiB 120,000 477 → 449 (−5.9%) 698 → 549 (−21.3%)

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 test passes with normal and forced-scalar dispatch (621 test executions each); cargo x check passes for native and x86_64-apple-darwin targets.

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @cijiugechu! LGTM.

@tisonkun
tisonkun merged commit 009b297 into fast:main Nov 18, 2026
13 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.

2 participants