feat: using smallvec (#6740)

Co-authored-by: Emilia Hane <emiliaha95@gmail.com>
This commit is contained in:
Luca Provini
2024-02-23 13:00:03 +01:00
committed by GitHub
parent 300336465c
commit 4c439e0b9a
5 changed files with 13 additions and 4 deletions

1
Cargo.lock generated
View File

@ -6973,6 +6973,7 @@ dependencies = [
"schnellru",
"serde",
"serde_json",
"smallvec",
"tempfile",
"thiserror",
"tokio",

View File

@ -224,6 +224,7 @@ hex-literal = "0.4"
once_cell = "1.17"
syn = "2.0"
nybbles = "0.1"
smallvec = "1.13"
# proc-macros
proc-macro2 = "1.0"

View File

@ -48,6 +48,7 @@ serde = { workspace = true, features = ["derive", "rc"], optional = true }
fnv = "1.0.7"
bitflags.workspace = true
auto_impl = "1.0"
smallvec.workspace = true
# testing
rand = { workspace = true, optional = true }

View File

@ -1,9 +1,10 @@
use crate::{
identifier::{SenderId, TransactionId},
pool::size::SizeTracker,
PoolTransaction, SubPoolLimit, ValidPoolTransaction,
PoolTransaction, SubPoolLimit, ValidPoolTransaction, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER,
};
use fnv::FnvHashMap;
use smallvec::SmallVec;
use std::{
cmp::Ordering,
collections::{hash_map::Entry, BTreeMap, BTreeSet},
@ -151,8 +152,12 @@ impl<T: ParkedOrd> ParkedPool<T> {
Some(tx.transaction.into())
}
/// Get transactions by sender
pub(crate) fn get_txs_by_sender(&self, sender: SenderId) -> Vec<TransactionId> {
/// Retrieves transactions by sender, using `SmallVec` to efficiently handle up to
/// `TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER` transactions.
pub(crate) fn get_txs_by_sender(
&self,
sender: SenderId,
) -> SmallVec<[TransactionId; TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER]> {
self.by_id
.range((sender.start_bound(), Unbounded))
.take_while(move |(other, _)| sender == other.sender)

View File

@ -25,6 +25,7 @@ use reth_primitives::{
},
Address, TxHash, B256,
};
use smallvec::SmallVec;
use std::{
cmp::Ordering,
collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet},
@ -366,7 +367,7 @@ impl<T: TransactionOrdering> TxPool<T> {
pub fn queued_and_pending_txs_by_sender(
&self,
sender: SenderId,
) -> (Vec<TransactionId>, Vec<TransactionId>) {
) -> (SmallVec<[TransactionId; TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER]>, Vec<TransactionId>) {
(self.queued_pool.get_txs_by_sender(sender), self.pending_pool.get_txs_by_sender(sender))
}