New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Reduce memory copying operations in bech32 encoding/decoding #29607
base: master
Are you sure you want to change the base?
refactor: Reduce memory copying operations in bech32 encoding/decoding #29607
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
6c6c228
to
4f76265
Compare
4f76265
to
db83766
Compare
f8fa74a
to
b3b84c3
Compare
Concept ACK I cherry-picked your last commit into #30047 to get rid of the hardcoded values inside |
7dd039a
to
b856835
Compare
Split the loop with two assignments to two loops
Overall resulting in decode being ~22% faster, encode ~32% faster. Before: ``` | ns/byte | byte/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 8.67 | 115,400,002.88 | 0.1% | 1.10 | `Bech32Decode` | 18.76 | 53,300,176.12 | 0.2% | 1.10 | `Bech32Encode` ``` After: ``` | ns/byte | byte/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 7.10 | 140,922,648.34 | 0.1% | 1.10 | `Bech32Decode` | 14.20 | 70,425,968.92 | 0.1% | 1.10 | `Bech32Encode` ```
b856835
to
00dc933
Compare
Started optimizing the base conversions in TryParseHex, Base58 and IsSpace - this is the next step.
Here I've reduced the memory reallocations and copying operations in bech32 encoding/decoding, resulting in decode being
~22%
faster, encode~32%
faster.Before:
After: