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

perf: avoid temporary Vec allocations when computing commitments #939

Merged
merged 8 commits into from
Nov 2, 2023

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented Nov 1, 2023


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

Copy link

codecov bot commented Nov 1, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (599644c) 67.73% compared to head (670c4b2) 67.80%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #939      +/-   ##
==========================================
+ Coverage   67.73%   67.80%   +0.07%     
==========================================
  Files         130      130              
  Lines       16397    16418      +21     
==========================================
+ Hits        11106    11133      +27     
+ Misses       5291     5285       -6     
Files Coverage Δ
crates/ibc/src/core/ics04_channel/commitment.rs 81.48% <100.00%> (+16.48%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mina86 mina86 force-pushed the a branch 2 times, most recently from 6a6c0f9 to e54a3a4 Compare November 1, 2023 06:32
Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

Thanks @mina86! Left a few suggestions.
Also, for our context, appreciate let us know what led to this change? Have you established any kind of benchmarks or obtained a preliminary estimate of the impact this change will have on your project's performance?

crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
sha2::Sha256::digest(data).to_vec()
}

#[test]
Copy link
Member

Choose a reason for hiding this comment

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

As for the tests, I’d like to have @rnbguy's input!

Copy link
Contributor Author

@mina86 mina86 Nov 2, 2023

Choose a reason for hiding this comment

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

The test here was purely to make sure that the output doesn’t change during refactoring. I can split this PR into two (one adding the test and the other doing the refactoring) if that’d help to demonstrate it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mina86 can you please put the tests under

#[cfg(test)]
mod test { ... }

and, make two separate tests for compute_packet_commitment and compute_ack_commitment?

@Farhad-Shabani Farhad-Shabani added the O: optimization Objective: aims to optimize performance, allocations and computations label Nov 2, 2023
@mina86
Copy link
Contributor Author

mina86 commented Nov 2, 2023

No, this was purely from looking at the code. I’ve done no benchmarks on it.

The reason why I was looking at the code was because I needed to make sure commitments are always 32-byte long.

By the way, ideally I’d like commitment to be struct PacketCommitment([u8; 32]); but that’s a completely different conversation (or struct PacketCommitment(Box<[u8; 32]>);; point is to have it fixed-size).

@Farhad-Shabani
Copy link
Member

No, this was purely from looking at the code. I’ve done no benchmarks on it.
The reason why I was looking at the code was because I needed to make sure commitments are always 32-byte long.

Alright, Gotcha.

By the way, ideally I’d like commitment to be struct PacketCommitment([u8; 32]); but that’s a completely different conversation (or struct PacketCommitment(Box<[u8; 32]>);; point is to have it fixed-size).

I see where you are coming from. Exactly, this is a totally different topic and a critical one. Better to surface it later when we have enough bandwidth to fully evaluate the changes around.

Copy link
Collaborator

@rnbguy rnbguy left a comment

Choose a reason for hiding this comment

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

Great PR, @mina86 ! 🙏 Just requested some changes.

crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
sha2::Sha256::digest(data).to_vec()
}

#[test]
Copy link
Collaborator

Choose a reason for hiding this comment

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

@mina86 can you please put the tests under

#[cfg(test)]
mod test { ... }

and, make two separate tests for compute_packet_commitment and compute_ack_commitment?

crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
.changelog/unreleased/improvements/939-less-alloc.md Outdated Show resolved Hide resolved
crates/ibc/src/core/ics04_channel/commitment.rs Outdated Show resolved Hide resolved
mina86 and others added 5 commits November 2, 2023 19:45
Co-authored-by: Rano | Ranadeep <[email protected]>
Signed-off-by: Michal Nazarewicz <[email protected]>
Co-authored-by: Rano | Ranadeep <[email protected]>
Signed-off-by: Michal Nazarewicz <[email protected]>
Co-authored-by: Rano | Ranadeep <[email protected]>
Signed-off-by: Michal Nazarewicz <[email protected]>
Co-authored-by: Rano | Ranadeep <[email protected]>
Signed-off-by: Michal Nazarewicz <[email protected]>
Copy link
Collaborator

@rnbguy rnbguy left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks @mina86 🤝

@Farhad-Shabani Farhad-Shabani merged commit ccca3ff into cosmos:main Nov 2, 2023
12 checks passed
@mina86 mina86 deleted the a branch November 2, 2023 20:01
Farhad-Shabani pushed a commit that referenced this pull request Sep 9, 2024
* perf: avoid temporary Vec allocations when computing commitments

* review

* Update crates/ibc/src/core/ics04_channel/commitment.rs

Co-authored-by: Rano | Ranadeep <[email protected]>
Signed-off-by: Michal Nazarewicz <[email protected]>

* Update crates/ibc/src/core/ics04_channel/commitment.rs

Co-authored-by: Rano | Ranadeep <[email protected]>
Signed-off-by: Michal Nazarewicz <[email protected]>

* Update crates/ibc/src/core/ics04_channel/commitment.rs

Co-authored-by: Rano | Ranadeep <[email protected]>
Signed-off-by: Michal Nazarewicz <[email protected]>

* review

* Update .changelog/unreleased/improvements/939-less-alloc.md

Co-authored-by: Rano | Ranadeep <[email protected]>
Signed-off-by: Michal Nazarewicz <[email protected]>

---------

Signed-off-by: Michal Nazarewicz <[email protected]>
Co-authored-by: Rano | Ranadeep <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O: optimization Objective: aims to optimize performance, allocations and computations
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants