perf: optimize pubkey generation by removing unnecessary constant-tim…#793
Closed
peiqing1998 wants to merge 1 commit intorust-bitcoin:masterfrom
peiqing1998:perf/pubkey-gen-opt
Closed
perf: optimize pubkey generation by removing unnecessary constant-tim…#793peiqing1998 wants to merge 1 commit intorust-bitcoin:masterfrom peiqing1998:perf/pubkey-gen-opt
peiqing1998 wants to merge 1 commit intorust-bitcoin:masterfrom
peiqing1998:perf/pubkey-gen-opt
Conversation
Member
|
As I mentioned in #792 -- you probably want to PR this upstream rather than here (in fact, our CI will reject these changes which make nontrivial changes to the vendored C code). I also don't believe that these changes are safe in general. But to consolidate discussion probably we want to discuss it on an upstream PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey folks.
Recently, while doing high frequency trading, I realized that the public key generation part could be faster.
I took a closer look at the code and found that some constant time operations in pubkey_create_helper can be optimized.
The change is very simple, that is, some of the operations that do not require constant time are replaced with variable time operations.
For example, scalar_set_b32_seckey is replaced by scalar_set_b32, ge_set_gej is replaced by ge_set_gej_var, and the use of constant time operations in these places is a bit of a killjoy.
The measured performance improvement is around 5-10%.
For high-frequency trading, a little bit faster is a little bit faster.
I have carefully reviewed the security aspects, the confidentiality is still confidential, just the fastest place to make it faster.
Benchmark numbers.
Before: ~123k pubkey/sec
After: ~132k pubkey/sec
Feel free to review and discuss any questions you may have.
Cheers!