apollo_consensus_orchestrator: use HashSet instead of IndexSet for duplicate-tx tracking#14856
Open
gkaempfer wants to merge 1 commit into
Open
Conversation
…plicate-tx tracking Follow-up performance review of #14840. The seen_tx_hashes set added to validate_proposal for duplicate-transaction detection is only ever inserted into and queried for membership, never iterated, so it gains nothing from IndexSet's insertion-order bookkeeping. Using a plain HashSet avoids that overhead on every transaction in every validated proposal. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PZ8grrsVcz9dQaaTWDafeT
PR SummaryLow Risk Overview Duplicate detection still uses Reviewed by Cursor Bugbot for commit 9affa3b. Bugbot is set up for automated code reviews on this repo. Configure here. |
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.
Summary
Follow-up performance review of #14840, scoped to the duplicate-transaction-hash tracking it added to the proposal validation hot path in
crates/apollo_consensus_orchestrator/src/validate_proposal.rs.#14840 introduced
seen_tx_hashes: IndexSet<TransactionHash>invalidate_proposal, populated once per transaction in every proposal part received during consensus proposal validation (handle_proposal_part) — a genuine per-transaction, per-block hot path.seen_tx_hashesis only ever inserted into and queried for membership (!seen_tx_hashes.insert(tx_hash)); it is never iterated or indexed anywhere in the file (verified viagrep -n "seen_tx_hashes" -r crates/apollo_consensus_orchestrator/src/).IndexSet(fromindexmap) exists specifically to provide insertion-order iteration, at the cost of an auxiliary dense-vector layer on top of the hash table — overhead this call site never benefits from. Swapping tostd::collections::HashSetremoves that bookkeeping from every transaction insertion, with a smaller memory footprint, while leaving behavior identical (insertreturnsbool= "was newly inserted" on both types;TransactionHash: Hash + Eqsatisfies both).The removed
use indexmap::IndexSet;was the only use ofIndexSetin this file;indexmapremains a dependency of the crate for unrelated usage elsewhere (cende/central_objects.rs).Test plan
cargo build -p apollo_consensus_orchestrator— cleanSEED=0 cargo test -p apollo_consensus_orchestrator— 177 passed, 0 failed, includingduplicate_transaction_hash_in_proposal_is_rejected_before_batcher, which exercises this exact code path🤖 Generated with Claude Code
Generated by Claude Code