Skip to content
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

perf: more FxHashMaps for SenderId key #13188

Merged
merged 1 commit into from
Dec 6, 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
10 changes: 3 additions & 7 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ use reth_execution_types::ChangedAccount;

use alloy_eips::eip4844::BlobTransactionSidecar;
use reth_primitives::RecoveredTx;
use std::{
collections::{HashMap, HashSet},
fmt,
sync::Arc,
time::Instant,
};
use rustc_hash::FxHashMap;
use std::{collections::HashSet, fmt, sync::Arc, time::Instant};
use tokio::sync::mpsc;
use tracing::{debug, trace, warn};
mod events;
Expand Down Expand Up @@ -216,7 +212,7 @@ where
fn changed_senders(
&self,
accs: impl Iterator<Item = ChangedAccount>,
) -> HashMap<SenderId, SenderInfo> {
) -> FxHashMap<SenderId, SenderInfo> {
let mut identifiers = self.identifiers.write();
accs.into_iter()
.map(|acc| {
Expand Down
9 changes: 5 additions & 4 deletions crates/transaction-pool/src/pool/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use crate::{
},
Priority, SubPoolLimit, TransactionOrdering, ValidPoolTransaction,
};
use rustc_hash::FxHashMap;
use std::{
cmp::Ordering,
collections::{hash_map::Entry, BTreeMap, HashMap},
collections::{hash_map::Entry, BTreeMap},
ops::Bound::Unbounded,
sync::Arc,
};
Expand Down Expand Up @@ -36,10 +37,10 @@ pub struct PendingPool<T: TransactionOrdering> {
by_id: BTreeMap<TransactionId, PendingTransaction<T>>,
/// The highest nonce transactions for each sender - like the `independent` set, but the
/// highest instead of lowest nonce.
highest_nonces: HashMap<SenderId, PendingTransaction<T>>,
highest_nonces: FxHashMap<SenderId, PendingTransaction<T>>,
/// Independent transactions that can be included directly and don't require other
/// transactions.
independent_transactions: HashMap<SenderId, PendingTransaction<T>>,
independent_transactions: FxHashMap<SenderId, PendingTransaction<T>>,
/// Keeps track of the size of this pool.
///
/// See also [`PoolTransaction::size`](crate::traits::PoolTransaction::size).
Expand Down Expand Up @@ -523,7 +524,7 @@ impl<T: TransactionOrdering> PendingPool<T> {

/// Returns a reference to the independent transactions in the pool
#[cfg(test)]
pub(crate) const fn independent(&self) -> &HashMap<SenderId, PendingTransaction<T>> {
pub(crate) const fn independent(&self) -> &FxHashMap<SenderId, PendingTransaction<T>> {
&self.independent_transactions
}

Expand Down
6 changes: 3 additions & 3 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl<T: TransactionOrdering> TxPool<T> {
/// Updates the transactions for the changed senders.
pub(crate) fn update_accounts(
&mut self,
changed_senders: HashMap<SenderId, SenderInfo>,
changed_senders: FxHashMap<SenderId, SenderInfo>,
) -> UpdateOutcome<T::Transaction> {
// track changed accounts
self.sender_info.extend(changed_senders.clone());
Expand All @@ -481,7 +481,7 @@ impl<T: TransactionOrdering> TxPool<T> {
&mut self,
block_info: BlockInfo,
mined_transactions: Vec<TxHash>,
changed_senders: HashMap<SenderId, SenderInfo>,
changed_senders: FxHashMap<SenderId, SenderInfo>,
update_kind: PoolUpdateKind,
) -> OnNewCanonicalStateOutcome<T::Transaction> {
// update block info
Expand Down Expand Up @@ -1180,7 +1180,7 @@ impl<T: PoolTransaction> AllTransactions<T> {
/// that got transaction included in the block.
pub(crate) fn update(
&mut self,
changed_accounts: HashMap<SenderId, SenderInfo>,
changed_accounts: FxHashMap<SenderId, SenderInfo>,
) -> Vec<PoolUpdate> {
// pre-allocate a few updates
let mut updates = Vec::with_capacity(64);
Expand Down
Loading