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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench/ssz.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Benchee.run(
time: 5
)

## Benchmark Merkleization
## Benchmark Merkleization

list = Stream.cycle([65_535]) |> Enum.take(316)
schema = {:list, {:int, 16}, 1024}
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda_ethereum_consensus/state_transition/misc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Misc do
first_8_bytes
end

@spec uint_to_bytes(non_neg_integer(), 8 | 32 | 64) :: binary()
@spec uint_to_bytes(non_neg_integer(), 8 | 16 | 32 | 64) :: binary()
def uint_to_bytes(value, size) do
# Converts an unsigned integer value to a bytes value
<<value::unsigned-integer-little-size(size)>>
Expand Down
1 change: 1 addition & 0 deletions lib/ssz_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

@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

def hash(data), do: :crypto.hash(:sha256, data)

Expand Down
1 change: 1 addition & 0 deletions lib/types/store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ defmodule Types.Store do
proposer_boost_root: Types.root() | nil,
equivocating_indices: MapSet.t(Types.validator_index()),
checkpoint_states: %{Checkpoint.t() => BeaconState.t()},
# NOTE: the `Checkpoint` values in latest_messages are `LatestMessage`s
latest_messages: %{Types.validator_index() => Checkpoint.t()},
Comment on lines +42 to 43
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

unrealized_justifications: %{Types.root() => Checkpoint.t()},
tree_cache: Tree.t()
Expand Down