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

Fixing performance issue by removing uneeded GroupElement conversions… #1056

Merged
merged 3 commits into from
Jul 21, 2021

Conversation

levonpetrosyan93
Copy link
Contributor

No description provided.

@levonpetrosyan93 levonpetrosyan93 requested review from a-bezrukov and psolstice and removed request for a-bezrukov July 19, 2021 10:13
@levonpetrosyan93 levonpetrosyan93 added this to the v0.14.7.1 milestone Jul 19, 2021
a-bezrukov
a-bezrukov previously approved these changes Jul 19, 2021
std::size_t GroupElement::lowest_limb() const {
secp256k1_fe x = reinterpret_cast<secp256k1_gej *>(g_)->x;
secp256k1_fe_normalize(&x);
return x.n[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

64-bit implementation of secp256k1 has 58-bit limb. This will not be uniform distribution in [0, SIZE_MAX] range (because it's less than 2^58). As a result (depending on implementation) unordered map/set may have just 1/64 buckets used decreasing performance. Examining C++ STL source is not for faint hearted so it's easier to just use for hash something like x.n[0] ^ (x.n[1] << 8) which will give you all bits in 64-bit integer and will be uniformly distributed. Then you need to rename it to something like get_hash()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

er, it's 52 bits and hence x.n[0] ^ (x.n[1] << 16) should be used. This will work both in 64-bit and 32-bit cases

@a-bezrukov a-bezrukov merged commit 7960de9 into master Jul 21, 2021
@a-bezrukov a-bezrukov deleted the performance_improve branch July 21, 2021 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants