Skip to content

perf: pre-initialized Blake2b cloning for hash hot paths#3089

Draft
wbbradley wants to merge 1 commit intowbbradley/further-investigationfrom
wbbradley/hash-initialization
Draft

perf: pre-initialized Blake2b cloning for hash hot paths#3089
wbbradley wants to merge 1 commit intowbbradley/further-investigationfrom
wbbradley/hash-initialization

Conversation

@wbbradley
Copy link
Contributor

@wbbradley wbbradley commented Mar 9, 2026

Description

Every leaf_hash and inner_hash call creates a fresh Blake2b256 hasher through new_with_params, which runs IV setup and parameter validation. With ~3M hash calls per 32 MiB encode (1M leaf + ~2M inner), this accounts for 1.1% of self-time in profiling.

This change bypasses HashFunctionWrapper in hot paths by working with blake2::Blake2b<U32> directly. Two static LazyLock hashers are pre-initialized with the leaf/inner prefix already fed in. Each hash call clones the pre-initialized state (~200 byte memcpy) instead of running full construction.

Adds leaf_hash_blake2b256 and inner_hash_blake2b256 as specialized fast-path functions, and MerkleTree::build_from_leaf_hashes_fast for Merkle tree construction. The generic leaf_hash<T> and inner_hash<T> remain unchanged for non-hot-path usage (proofs, generic tree builds).

Test plan

  • CI Pipeline
  • Benchmarked with profile_encoding; results are within noise of the previous commit, consistent with the small (~1%) targeted overhead.

Release notes

  • Storage node:
  • Aggregator:
  • Publisher:
  • CLI:

@wbbradley wbbradley marked this pull request as draft March 9, 2026 04:28
@wbbradley wbbradley force-pushed the wbbradley/further-investigation branch from 7d38f81 to 9d1f54f Compare March 9, 2026 04:34
@wbbradley wbbradley force-pushed the wbbradley/hash-initialization branch from 4fb1826 to 6ee5104 Compare March 9, 2026 05:01
@wbbradley wbbradley force-pushed the wbbradley/further-investigation branch from 9d1f54f to f0f01c0 Compare March 9, 2026 14:11
@wbbradley wbbradley force-pushed the wbbradley/hash-initialization branch from 6ee5104 to 3fd08b0 Compare March 9, 2026 14:11
@wbbradley wbbradley force-pushed the wbbradley/further-investigation branch 2 times, most recently from f0dc785 to b7f6cc2 Compare March 9, 2026 17:49
@wbbradley wbbradley force-pushed the wbbradley/hash-initialization branch from 3fd08b0 to a6c5085 Compare March 9, 2026 17:59
@wbbradley wbbradley force-pushed the wbbradley/further-investigation branch from b7f6cc2 to c7a8cc4 Compare March 10, 2026 00:51
@wbbradley wbbradley force-pushed the wbbradley/hash-initialization branch from a6c5085 to 606c1c1 Compare March 10, 2026 00:51
@wbbradley wbbradley force-pushed the wbbradley/further-investigation branch from c7a8cc4 to b21a0fb Compare March 10, 2026 03:33
@wbbradley wbbradley force-pushed the wbbradley/hash-initialization branch from 606c1c1 to f9e63d8 Compare March 10, 2026 03:33
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.

1 participant