neo icon indicating copy to clipboard operation
neo copied to clipboard

Base58 perfomance patch

Open kzorin52 opened this issue 2 years ago • 24 comments

Description

Various Base58 performance improvements:

Decode():

  1. Replaced slow IndexOf() to Base58 character map
  2. Replaced .TakeWhile(...).Count() to efficient variant, without memory and cpu-time loss
  3. Replaced byte[] Concat() to single Span<byte>
  4. Fixed: zeros byte array creation only if decoded is zero

Type of change

  • [x] Bug fix (non-breaking change)

How Has This Been Tested?

  • [x] UT_Base58.TestEncodeDecode
  • [x] UT_StdLib.TestBinary

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my code
  • [ ] I have commented my code, particularly in hard-to-understand areas - no hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation - public API do not changed
  • [x] My changes generate no new warnings
  • [ ] I have added tests that prove my fix is effective or that my feature works - benchmarks only
  • [x] New and existing unit tests pass locally with my changes
  • [ ] Any dependent changes have been merged and published in downstream modules - no dependent changes

P.S. It is my first time opening a pull request, please correct me if I've done something wrong.

kzorin52 avatar Mar 28 '24 14:03 kzorin52

@kzorin52 thank you very much for contributing to neo. This pr looks good to me.

@cschuchardt88 @shargon @AnnaShaleva @vncoelho

Jim8y avatar Mar 28 '24 17:03 Jim8y

@shargon all fixed 🥳

kzorin52 avatar Mar 29 '24 08:03 kzorin52

@cschuchardt88 Okay, I'll do benchmarks and profiling of the code

kzorin52 avatar Mar 30 '24 16:03 kzorin52

I'm sorry, I've been really busy lately. As soon as I have free time, I will be able to make the planned benchmarks.

kzorin52 avatar Apr 23 '24 06:04 kzorin52