perf: more FxHashMaps for SenderId key (#13188)

This commit is contained in:
Hai | RISE
2024-12-07 03:35:30 +07:00
committed by GitHub
parent c608679963
commit a0326e4f86
3 changed files with 11 additions and 14 deletions

View File

@ -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;
@ -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| {

View File

@ -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,
};
@ -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).
@ -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
}

View File

@ -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());
@ -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
@ -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);