perf: reduce allocations in lean block import and head computation#1447
Open
zemse wants to merge 2 commits into
Open
perf: reduce allocations in lean block import and head computation#1447zemse wants to merge 2 commits into
zemse wants to merge 2 commits into
Conversation
update_head and produce_block_with_signatures iterated the entire latest_known_aggregated_payloads table and SSZ-decoded every Vec<PayloadProof> on each call, but the only consumer reads just the validator id and attestation data root from the key. The proof values were never used. Add iter_keys and entry_count to the table so callers read keys and the entry count without decoding the (large) proof payloads, and take the keys in extract_attestations_from_aggregated_payloads. Keys are only ever stored with a non-empty proof list, so the previous emptiness check is preserved by construction.
The block table's insert took the SignedBlock by value, so on_block cloned the whole block (carrying the large post-quantum signatures) to hand it over, and the table then cloned it again for its cache. Add LeanBlockTable::insert_ref so on_block passes the block by reference and the value is serialized in place. The owned insert now delegates to it, leaving one clone only when the cache is enabled.
0cff069 to
45dcb21
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What was wrong?
Two hot paths in the lean node allocated far more than necessary on every block and tick:
update_headandproduce_block_with_signaturesiterated the entirelatest_known_aggregated_payloadstable and SSZ-decoded everyVec<PayloadProof>(the large post-quantum signatures) on each call. The only consumer reads just the
validator id and attestation data root from each key, so the proof values were
decoded and thrown away.
on_blockcloned the wholeSignedBlock, carrying those same large signatures,just to hand it to the block store, which then cloned it again for its cache.
How was it fixed?
iter_keys()andentry_count()to the payloads table so callers read thekeys and the entry count without decoding the proof values, and changed
extract_attestations_from_aggregated_payloadsto take&[SignatureKey]. Theprevious
is_empty()skip is preserved by construction: both insert sites only everstore non-empty proof lists.
LeanBlockTable::insert_refsoon_blockpasses the block by reference andredb serializes it in place; the owned
insertnow delegates to it.No behavior change. Measured on a single-node devnet-4 (60s):
produce_block_with_signatures~22 MB -> ~40 KB per call,
update_head~15 MB -> ~4 MB per call, total processallocation churn ~8.4 GB -> ~7.3 GB.
To-Do