descriptor: speed-up `Parse` (xpub/xpriv) in ~30% #35041

pull brunoerg wants to merge 2 commits into bitcoin:master from brunoerg:2026-04-descriptor changing 5 files +65 −28
  1. brunoerg commented at 6:19 PM on April 9, 2026: contributor

    This PR speeds up descriptor parsing, for basically descriptors that use xpub/xpriv, through some targeted improvements (I've been working on fuzz targets for wallet stuff for a while. I've noticed that some of them are slow so I started to work on understanding why and improve what can be improved. The finding came from it):

    • Avoid redundant base58 decoding when parsing extended keys (this is the major improvement)

      ParsePubkeyInner unconditionally called both DecodeExtKey() and DecodeExtPubKey(), each running a full DecodeBase58Check (two SHA256 passes over ~111 bytes). A new DecodeExtKeyOrPubKey() function performs a single base58 decode and then checks the prefix, halving the cryptographic work per key. The interfaces of DecodeSecret, DecodeExtKey, and DecodeExtPubKey are also updated to accept string_view instead of const std::string&, eliminating unnecessary string copies in the descriptor parser and allowing DecodeBase58/DecodeBase58Check to use pointer-range iteration instead of strlen.

    • Replace O(n) charset lookup with precomputed table

      DescriptorChecksum previously called std::string::find() for every character in the descriptor string, doing up to 96 comparisons per character. This replaces it with a 256-entry precomputed lookup table for O(1) lookups. The benefit scales with descriptor length.


    Parse() with the following descriptor:

    tr(xpub6CGCzpvrZVssNNXuP1Awcz8GoakYyJHra2WHASXfCzsD9szbQFoT1pLMdQopyqaSqXUprH7fkk8NG2pUbQa5HpNzpWmEsdNZDHxXvSLPTrn/*,{{multi_a(20,xpub6CGCzpvrZVssNNXuP1Awcz8GoakYyJHra2WHASXfCzsD9szbQFoT1pLMdQopyqaSqXUprH7fkk8NG2pUbQa5HpNzpWmEsdNZDHxXvSLPTrn/*,xpub6C5MW95EE8hAmxm96LdAFYkweaAktQoojCf2MwJmNL9Fi6oUPeBnpFdEzhs9zHwr4HQEeF1r1yAUR8MqDJqk4YPteh75rNoCKCtud7shDDk/*,xpub6DNEUJP1zLAZ1P6gYRba9FyxuppmkrPmSKz3FLM7msRwn2LEr4LnKfAnNoSoAbnbW2orTfsitdfWTxLbJCZ6Liz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yqzQe99Uiyxpfy1ow42xUGpPGBHf8ErxDbQojBf7Uy7hKFgYk8KpgMm2/*,xpub6DQ2qVMZ2o2QGGpYDsw5hpAcygNVEycAkkCib2Lexwm8gYWMCSecZ256AbAV93Rgze6h8yEoTcqUnvnz7L69WUqp7cXd85X8HoeKWjPHRRZ/*)}})
    

    This PR:

    |               ns/op |                op/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |           90,253.50 |           11,079.90 |    0.2% |      0.01 | `ParseDescriptor`
    

    Master:

    |               ns/op |                op/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |          127,812.50 |            7,823.96 |    0.5% |      0.01 | `ParseDescriptor`
    

    I didn't put the benchmark itself here but if reviewers think worth, I can do it.


    Joint work with claude 😅

  2. DrahtBot added the label Descriptors on Apr 9, 2026
  3. brunoerg marked this as a draft on Apr 9, 2026
  4. DrahtBot commented at 6:19 PM on April 9, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35041.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK sedited

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • DecodeBase58Check(str, data, 78) in src/key_io.cpp

    <sup>2026-06-10 17:52:05</sup>

  5. brunoerg marked this as ready for review on Apr 9, 2026
  6. l0rinc commented at 8:39 PM on April 9, 2026: contributor

    Avoid redundant base58 decoding when parsing extended keys (this is the major improvement)

    There have been a few base58 optimization attempts before (https://github.com/bitcoin/bitcoin/pull/29473 and independently before #21176) - would it help if we revived them?

  7. brunoerg commented at 12:08 PM on April 10, 2026: contributor

    Avoid redundant base58 decoding when parsing extended keys (this is the major improvement)

    There have been a few base58 optimization attempts before (#29473 and independently before #21176) - would it help if we revived them?

    I'll take a look on those PRs and try, thank you. I think their focus is to improve/rewrites the algorithm itself, here is more about the way it's been used.

  8. sedited requested review from hodlinator on Apr 20, 2026
  9. in src/script/descriptor.cpp:127 in 2d86114c1b
     123 |          "0123456789()[],'/*abcdefgh@:$%{}"
     124 |          "IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~"
     125 |          "ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ";
     126 |  
     127 | +    /** Lookup table mapping each ASCII byte to its position in INPUT_CHARSET, or -1 if not present. */
     128 | +    static const std::array<int, 256> INPUT_CHARSET_POS = []() {
    


    sedited commented at 1:53 PM on June 7, 2026:

    Shouldn't really matter, but I thinks this could be constexpr too.


    brunoerg commented at 3:52 PM on June 10, 2026:

    Done.

  10. sedited commented at 2:04 PM on June 7, 2026: contributor

    Concept ACK

  11. descriptor, key_io: avoid redundant work when parsing keys
    In ParsePubkeyInner, every extended key required two full base58
    decodes: once via DecodeExtKey and again via DecodeExtPubKey, even
    though at most one can succeed. Replace both calls with a new
    DecodeExtKeyOrPubKey helper that performs a single DecodeBase58Check
    and dispatches on the 4-byte version prefix to populate either the
    xprv or xpub result.
    
    Also eliminate the per-key std::string allocation in ParsePubkeyInner
    by switching the local 'str' variable to std::string_view over the
    existing span, and update DecodeSecret / DecodeExtKey / DecodeExtPubKey
    to accept std::string_view directly (std::string and const char* callers
    are unaffected via implicit conversion).
    
    To allow the string_view path all the way down, the internal base58
    decoder is refactored from null-terminated const char* to a (psz, end)
    pointer pair, replacing strlen() and *psz null checks with pointer
    comparisons. The public DecodeBase58 / DecodeBase58Check APIs now take
    std::string_view as well.
    d719bb8844
  12. brunoerg force-pushed on Jun 10, 2026
  13. DrahtBot added the label CI failed on Jun 10, 2026
  14. DrahtBot commented at 5:18 PM on June 10, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/27288256306/job/80601410847</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU detected missing/incorrect includes in src/script/descriptor.cpp (autofix ran and then the IWYU check failed).</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  15. descriptor: replace O(n) INPUT_CHARSET.find() with precomputed lookup table
    Replace the O(n) linear INPUT_CHARSET.find() in DescriptorChecksum with
    a precomputed 256-entry lookup table, reducing the checksum pass from
    O(95 * len) to O(len).
    6dd023abbc
  16. brunoerg force-pushed on Jun 10, 2026
  17. DrahtBot removed the label CI failed on Jun 10, 2026


hodlinator


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-06-17 21:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me