Skip to content

perf: inline SszEx.hash function #722

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

Merged
merged 1 commit into from
Feb 7, 2024
Merged

perf: inline SszEx.hash function #722

merged 1 commit into from
Feb 7, 2024

Conversation

MegaRedHand
Copy link
Collaborator

Since the function is just an "alias" to :crypto.hash, we can safely inline all calls. This gives a ~5% performance increase when hashing, according to benchmarks.

@MegaRedHand MegaRedHand requested a review from a team as a code owner February 6, 2024 21:07
Comment on lines +42 to 43
# NOTE: the `Checkpoint` values in latest_messages are `LatestMessage`s
latest_messages: %{Types.validator_index() => Checkpoint.t()},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was puzzled by this when working on other things, so I added this comment

@MegaRedHand MegaRedHand self-assigned this Feb 6, 2024
@MegaRedHand MegaRedHand added the perf performance-related PRs or issues label Feb 6, 2024
@@ -18,6 +18,7 @@ defmodule LambdaEthereumConsensus.SszEx do
@zero_chunk <<0::size(@bits_per_chunk)>>
@zero_hashes ZeroHashes.compute_zero_hashes()

@compile {:inline, hash: 1}
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL

@@ -18,6 +18,7 @@ defmodule LambdaEthereumConsensus.SszEx do
@zero_chunk <<0::size(@bits_per_chunk)>>
@zero_hashes ZeroHashes.compute_zero_hashes()

@compile {:inline, hash: 1}
@spec hash(iodata()) :: binary()
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldnt this function live outside of SSZ? I see it's being used in other places too, like shuffling

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe. We just added it here since adding a new module for this function seemed like too much

@MegaRedHand MegaRedHand merged commit e01f275 into main Feb 7, 2024
@MegaRedHand MegaRedHand deleted the inline-ssz-hash branch February 7, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf performance-related PRs or issues
Projects
Development

Successfully merging this pull request may close these issues.

2 participants