refactor: Optimize bech32::Encode #13632

pull Empact wants to merge 1 commits into bitcoin:master from Empact:bech32-encode-char changing 2 files +21 −7
  1. Empact commented at 8:54 AM on July 11, 2018: member

    This is my treatment of @kallewoof's #13586

    I got another big win out of not catting together the values and checksum for iteration, and a small win from using pre-increment.

    This results in a ~40% speed-up in calls to Encode()

    Before:

      #Benchmark, evals, iterations, total, min, max, median
      Bech32Encode, 5, 800000, 5.98941, 1.46948e-06, 1.56082e-06, 1.49065e-06
    

    After:

      #Benchmark, evals, iterations, total, min, max, median
      Bech32Encode, 5, 800000, 3.60337, 8.82574e-07, 9.23948e-07, 8.93568e-07
    

    Also throwing a std::length_error on length error, rather than asserting, for easier error handling.

    This PR brought to you by insomnia.

  2. fanquake added the label Refactoring on Jul 11, 2018
  3. kallewoof commented at 9:05 AM on July 11, 2018: member

    You could cherry pick my benchmark as a separate commit since you seem to be using it as is (189cf35f3e6d2cc9ed08eb23dd0ea36be28b6c11).

    Keeping bench and speed-up as separate commits is useful as you can compare easier.

  4. Empact force-pushed on Jul 11, 2018
  5. Empact commented at 9:08 AM on July 11, 2018: member

    @kallewoof Could you restore the branch? As of now it's on github but comes up as "fatal: bad object 189cf35f3e6d2cc9ed08eb23dd0ea36be28b6c11" via git.

  6. kallewoof commented at 9:21 AM on July 11, 2018: member

    Done

  7. Empact force-pushed on Jul 11, 2018
  8. Empact force-pushed on Jul 11, 2018
  9. laanwj referenced this in commit acc68bc631 on Jul 11, 2018
  10. refactor: Optimize bech32::Encode
    * switch from std::string to using char[]
    * iterate over values and checksum separately rather than comining
      them first
    
    This results in a ~40% speed-up in calls to Encode()
    
    Before:
      #Benchmark, evals, iterations, total, min, max, median
      Bech32Encode, 5, 800000, 5.98941, 1.46948e-06, 1.56082e-06, 1.49065e-06
    
    After:
      #Benchmark, evals, iterations, total, min, max, median
      Bech32Encode, 5, 800000, 3.60337, 8.82574e-07, 9.23948e-07, 8.93568e-07
    
    With kallewoof
    fcb42530da
  11. Empact force-pushed on Jul 11, 2018
  12. DrahtBot commented at 12:05 PM on July 11, 2018: member

    <!--e57a25ab6845829454e8d69fc972939a-->Note to reviewers: This pull request conflicts with the following ones:

    • #13249 (Make objects in range declarations immutable by default. Avoid unnecessary copying of objects in range declarations. by practicalswift)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  13. Empact commented at 5:10 PM on July 11, 2018: member

    Closing as per IRC comments that the current implementation "was made for simplicity and readability", "is not on the critical path", etc.

  14. Empact closed this on Jul 11, 2018

  15. Empact deleted the branch on Jul 11, 2018
  16. PastaPastaPasta referenced this in commit 357164dcb7 on Jun 27, 2021
  17. PastaPastaPasta referenced this in commit 5937d23ae6 on Jun 28, 2021
  18. PastaPastaPasta referenced this in commit c70ef4cbd4 on Jun 28, 2021
  19. PastaPastaPasta referenced this in commit 3c0bda8e15 on Jun 28, 2021
  20. PastaPastaPasta referenced this in commit c7c810772d on Jun 28, 2021
  21. PastaPastaPasta referenced this in commit 097bde6377 on Jun 29, 2021
  22. MarcoFalke locked this on Sep 8, 2021

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-04-14 21:14 UTC

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