Most base58 strings in Bitcoin are somewhat short. There was previously an "optimization" putting part of the input on stack which was removed in #2759 because it actually made the code slower. This appears to be mostly because of branches caused by using `iter::Chain`. Manually splitting the iterations into two helped bring the performance close to what #2759 achieved but that still wasn't worth it. But given that we know the input length in many cases (it's just a slice) we can determine whether it'll fit a buffer upfront and then just call different functions which don't have the branches in loops. To avoid having two functions this uses generics instead. Further, we increase the buffer length to 128 and use `ArrayVec` from `internals` which internally avoids initializing the buffer thanks to `MaybeUninit` In total this increases performance by around 4% on my machine. |
||
---|---|---|
.. | ||
contrib | ||
src | ||
CHANGELOG.md | ||
Cargo.toml | ||
README.md |
README.md
Bitcoin base58 encoding
This crate provides encoding and decoding of base58 strings as defined by the Bitcoin ecosystem including the checksum.
There are a bunch of crates on crates.io that implement base58 encoding and decoding. The more obviously named ones differ from this crate because:
-
bitcoin-base58 is transpiled from the C++ code in Bitcoin Core as part of a large long-term transpilation project, whereas this crate is a pure Rust implementation intended to be production-ready and to provide an Rust-idiomatic API.
-
base58 implements parsing but does not validate checksums (see
base58check
). It may be appropriate in cases where performance is more important than safety. Appears unmaintained. -
base58check Adds checksum to the
base58
crate and depends on sha2 for hashing. Appears unmaintained.
This crate uses bitcoin_hashes when hashing to calculate the checksum.
Minimum Supported Rust Version (MSRV)
This library should always compile with any combination of features on Rust 1.56.1.
Licensing
The code in this project is licensed under the Creative Commons CC0 1.0 Universal license. We use the SPDX license list and SPDX IDs.