Improve base-32 hash decoding performance with reverse map#13680
Improve base-32 hash decoding performance with reverse map#13680Ericson2314 merged 1 commit intoNixOS:masterfrom
Conversation
Ericson2314
left a comment
There was a problem hiding this comment.
Thanks for this! This is indeed much better: faster and clearer.
Just one small thing, then let's land it!
The changes include: * Defining nix32Chars as a constexpr char[]. * Adding a constexpr std::array<unsigned char, 256> (reverseNix32Map) to map characters to their base-32 digit values at compile time. * Replacing the slow character search loop with a direct lookup using reverseNix32Map. * Removing std::once_flag/isBase32 logic in references.cc in favor of reverseNix32Map Signed-off-by: Alexander V. Nikolaev <avn@avnik.info>
cad1d68 to
4bfc007
Compare
|
@Ericson2314 your suggestion applied |
|
I wouldn't mind if we could add a benchmark for this, but this could be done in a follow-up. |
|
@xokdvium also wouldn't be bad to add dedicated tests for both nix32 encoding/decoding |
Absolutely. If you'd like you could handle it in a separate PR. Any help with the test coverage would be greatly appreciated. |
|
Note re #13682 that this PR is not supposed to affect how reference scanning works. It just affects how the parsing of hashes themselves (a |
Ericson2314
left a comment
There was a problem hiding this comment.
I talked to @xokdvium, and we can just do the rest in a follow-up PR.
|
We are working on this now, so don't sweat @avnik. |
Motivation
This PR replaces the linear search over nix32Chars with a constexpr-initialized reverse lookup table for decoding base-32 hashes. The changes include:
This significantly improves performance and clarity of base-32 decoding logic, while preserving correctness.