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

Avoid unnecessary copying and dynamic memory allocations #4261

Closed
wants to merge 1 commit into from
Closed

Avoid unnecessary copying and dynamic memory allocations #4261

wants to merge 1 commit into from

Conversation

nbougalis
Copy link
Contributor

This commit implements an optimization that @chennakeshava1998 and I identified; this commit reduces unnecessary dynamic memory allocations when processing proposals.

Co-authored-by: Chenna Keshava B S <ckbs.keshava56@gmail.com>
Comment on lines +224 to +225
if (sig.size() == 0)
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this added check is needed as this is taken care of by ecdsaCanonicality below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'll remove it.

PublicKey publicKey_;
uint256 suppression_;
Proposal proposal_;
boost::container::static_vector<std::uint8_t, 72> signature_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a hypothetical question. If the size of the signature_ variable was a multiple of 32 bytes, then
can we use a ripple::base_uint<33> for storing the signature_ data? Will that be slower than boost::static_vector?

Is one of them faster than the other?

Copy link
Contributor

@greg7mdp greg7mdp Aug 3, 2022

Choose a reason for hiding this comment

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

ripple::base_uint<33> would not work as it specifies 33 bits (you need 72 bytes or 72 x 8 bits), and it is designed to store uint32_t not an array of bytes. Also base_uint doesn't manage a size, so you'd have to keep track separately of how long the signature is. static_vector is the right choice here!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see okay, thanks for the clarification.

@nbougalis nbougalis mentioned this pull request Aug 4, 2022
Copy link
Contributor

@HowardHinnant HowardHinnant left a comment

Choose a reason for hiding this comment

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

Nice job.

@nbougalis nbougalis mentioned this pull request Aug 9, 2022
@nbougalis nbougalis deleted the rclcxpeerpos branch October 16, 2023 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants