Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

paplorinc
Copy link
Contributor

@paplorinc paplorinc commented Mar 9, 2024

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:

|             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`

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 9, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK josibake

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@paplorinc paplorinc force-pushed the paplorinc/bech32_optimizations branch from 6c6c228 to 4f76265 Compare March 9, 2024 13:16
@paplorinc paplorinc marked this pull request as ready for review March 9, 2024 14:28
@paplorinc paplorinc force-pushed the paplorinc/bech32_optimizations branch from 4f76265 to db83766 Compare April 21, 2024 10:46
@paplorinc paplorinc marked this pull request as draft April 21, 2024 11:53
@paplorinc paplorinc force-pushed the paplorinc/bech32_optimizations branch 10 times, most recently from f8fa74a to b3b84c3 Compare April 22, 2024 10:31
@paplorinc paplorinc marked this pull request as ready for review April 22, 2024 12:57
@josibake
Copy link
Member

Concept ACK

I cherry-picked your last commit into #30047 to get rid of the hardcoded values inside ExpandHRP. Looking at the rest of your commits here, the rest of the changes look great and the benchmark numbers are a nice improvement. Will review more thoroughly this week!

@paplorinc paplorinc force-pushed the paplorinc/bech32_optimizations branch 2 times, most recently from 7dd039a to b856835 Compare May 12, 2024 12:05
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`
```
@paplorinc paplorinc force-pushed the paplorinc/bech32_optimizations branch from b856835 to 00dc933 Compare May 13, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants