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

Use .NET 5's HEX function #9561

Merged
merged 2 commits into from Nov 17, 2022

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented Nov 17, 2022

This PR aligns us with .NET and uses Convert.FromHexString which is vectorized in .NET, so we should observe significant speedup (see MetacoSA/NBitcoin#1149 for some numbers).

Current master implementation

|  Method |      Mean |    Error |   StdDev |
|-------- |----------:|---------:|---------:|
|   ToHex |  25.19 ns | 0.501 ns | 1.355 ns |
| FromHex | 563.06 ns | 4.742 ns | 3.702 ns |

This PR: Only first commit:

|  Method |     Mean |    Error |   StdDev |
|-------- |---------:|---------:|---------:|
|   ToHex | 35.58 ns | 0.171 ns | 0.152 ns |
| FromHex | 71.38 ns | 0.650 ns | 0.576 ns |

This PR: All commits

|  Method |     Mean |    Error |   StdDev |
|-------- |---------:|---------:|---------:|
|   ToHex | 25.80 ns | 0.474 ns | 1.180 ns |
| FromHex | 75.86 ns | 1.552 ns | 1.963 ns |

Benchmark is here, use in WalletWasabi.Tests folder:

dotnet run -c Release --framework net6.0 -- --runtimes net6.0

With this PR, we can replace https://github.com/zkSNACKs/WalletWasabi/blob/master/WalletWasabi/Backend/Models/FilterModel.cs#L47 to use our new implementation and it can shave a bit of time from startup. Fundamentally, we should tackle it differently, but given current consensus, this is what we can do.

@kiminuo kiminuo marked this pull request as ready for review November 17, 2022 14:23
@kiminuo kiminuo changed the title Use .NET 5's HEX functions Use .NET 5's HEX function Nov 17, 2022
@turbolay
Copy link
Collaborator

turbolay commented Nov 17, 2022

ByteHelpers.FromHex(): 0.01162376 ms / read a compact filter
Encoders.Hex.DecodeData(): 0.01115517 ms / read a compact filter

-> No difference for the main operation that is using this because the NBitcoin implementation is already fast.
Yet, it's more compact and faster that the code we currently have.

@lontivero lontivero merged commit 2f373d6 into zkSNACKs:master Nov 17, 2022
@kiminuo kiminuo deleted the feature/2022-11-17-fast-HEX-ops branch November 17, 2022 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants