-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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 #29607
base: master
Are you sure you want to change the base?
refactor: Reduce memory copying operations in bech32 encoding #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
b856835
to
00dc933
Compare
00dc933
to
1048dd6
Compare
1d96f43
to
aa396df
Compare
aa396df
to
f45539c
Compare
f45539c
to
ec0261d
Compare
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
ec0261d
to
d9586d6
Compare
814c05e
to
e7c55d4
Compare
@josibake, now that the cherry-pick was merged, I've rebased and re-measured - the important part of this change was already included in the other PR, the remaining optimizations here are smaller, but also a lot simpler. |
Here I've reduced the memory reallocations and copying operations in bech32 encode, making it ~15% faster. make && ./src/bench/bench_bitcoin --filter='Bech32Encode' --min-time=1000 Before: | ns/byte | byte/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 19.97 | 50,074,562.72 | 0.1% | 1.06 | `Bech32Encode` After: | ns/byte | byte/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 17.33 | 57,687,668.20 | 0.1% | 1.10 | `Bech32Encode` Co-authored-by: josibake <josibake@protonmail.com>
e7c55d4
to
07f6417
Compare
ACK 07f6417 Verified the benchmark locally. Aside from the speed improvements, this also improves the readability of the code. |
utACK 07f6417 Making the code more readable is a good reason to make this change, but this code was specifically written to prioritize simplicity over performance. If we'd care about performance, it's probably better to use an approach similar to that of the C reference implementation (as it works entirely on the stack, while the current code does several allocations: 1 in |
Started optimizing the base conversions in TryParseHex, Base58 and IsSpace - this is the next step.
Part of this change was already merged in #30047, which made decoding
~26%
faster.Here I've reduced the memory reallocations and copying operations in bech32 encode, making it
~15%
faster.Before:
After: