You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR contains two small performance optimizations in alloy-primitives focused on bloom membership checks and bitset containment.
Commits
590dcc1 perf: avoid temporary bitset in FixedBytes covers
Rewrites FixedBytes::covers to reduce directly over paired bytes instead of computing (*self & *other) == *other.
This avoids materializing an intermediate fixed-byte value and lets optimized builds lower bloom containment to a tighter byte/vector reduction.
1ed997c perf: avoid temporary blooms in membership checks
Updates bloom membership helpers to test the three Ethereum bloom bits directly.
This avoids constructing temporary Bloom values in:
Bloom::contains_input
Bloom::contains_raw_log
It also routes Bloom::accrue through the existing pre-hashed m3_2048_hashed helper, adds concise documentation for the direct bit-index extraction, and replaces the raw-log containment example with a proptest that compares the direct path against the old temporary-bloom behavior for arbitrary blooms, addresses, and topic lists.
After (PR): tests the three bloom bits from each hash directly. The printed function body is larger because the hash/check loop is now inlined instead of hidden behind accrue_raw_log, but the temporary bloom construction and final _memcmp are gone, and failed bit checks can return early.
Takeaway: the FixedBytes::covers change is a clear codegen win for bloom containment: it removes the 256-byte temporary and the _memcmp call. The contains_raw_log change removes the temporary bloom path and checks membership directly; raw inputs remain Keccak-bound, but the non-hash work is reduced and can short-circuit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR contains two small performance optimizations in
alloy-primitivesfocused on bloom membership checks and bitset containment.Commits
590dcc1 perf: avoid temporary bitset in FixedBytes covers
Rewrites
FixedBytes::coversto reduce directly over paired bytes instead of computing(*self & *other) == *other.This avoids materializing an intermediate fixed-byte value and lets optimized builds lower bloom containment to a tighter byte/vector reduction.
1ed997c perf: avoid temporary blooms in membership checks
Updates bloom membership helpers to test the three Ethereum bloom bits directly.
This avoids constructing temporary
Bloomvalues in:Bloom::contains_inputBloom::contains_raw_logIt also routes
Bloom::accruethrough the existing pre-hashedm3_2048_hashedhelper, adds concise documentation for the direct bit-index extraction, and replaces the raw-log containment example with a proptest that compares the direct path against the old temporary-bloom behavior for arbitrary blooms, addresses, and topic lists.Verification
cargo +nightly fmt --all --checkRUSTDOCFLAGS="--cfg docsrs -D warnings -Zunstable-options --show-type-layout --generate-link-to-definition" cargo +nightly doc --workspace --all-features --no-deps --document-private-itemscargo test -p alloy-primitives bits::bloom --libcargo test -p alloy-primitives --no-default-features bits::bloom --libcargo +nightly test -p alloy-primitives --all-features contains_raw_log_matches_bloom_contains --libRUSTFLAGS=-Dwarnings cargo +nightly clippy -p alloy-primitives --all-targets --all-featuresEarlier full-branch verification before the test/doc amend also passed:
cargo test --workspacecargo test --workspace --no-default-featurescargo +nightly test --workspace --all-features