mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-10 07:48:19 -05:00
perf: wrap tx with Arc to avoid deep cloning (#19350)
This commit is contained in:
@@ -318,7 +318,7 @@ where
|
||||
let (execute_tx, execute_rx) = mpsc::channel();
|
||||
self.executor.spawn_blocking(move || {
|
||||
for tx in transactions {
|
||||
let tx = tx.map(|tx| WithTxEnv { tx_env: tx.to_tx_env(), tx });
|
||||
let tx = tx.map(|tx| WithTxEnv { tx_env: tx.to_tx_env(), tx: Arc::new(tx) });
|
||||
// only send Ok(_) variants to prewarming task
|
||||
if let Ok(tx) = &tx {
|
||||
let _ = prewarm_tx.send(tx.clone());
|
||||
|
||||
@@ -521,7 +521,7 @@ where
|
||||
done_tx: Sender<()>,
|
||||
) -> mpsc::Sender<IndexedTransaction<Tx>>
|
||||
where
|
||||
Tx: ExecutableTxFor<Evm> + Clone + Send + 'static,
|
||||
Tx: ExecutableTxFor<Evm> + Send + 'static,
|
||||
{
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let ctx = self.clone();
|
||||
|
||||
@@ -23,14 +23,14 @@ pub trait ExecutableTxIterator<Evm: ConfigureEvm>:
|
||||
Iterator<Item = Result<Self::Tx, Self::Error>> + Send + 'static
|
||||
{
|
||||
/// The executable transaction type iterator yields.
|
||||
type Tx: ExecutableTxFor<Evm> + Clone + Send + 'static;
|
||||
type Tx: ExecutableTxFor<Evm> + Clone + Send + Sync + 'static;
|
||||
/// Errors that may occur while recovering or decoding transactions.
|
||||
type Error: core::error::Error + Send + Sync + 'static;
|
||||
}
|
||||
|
||||
impl<Evm: ConfigureEvm, Tx, Err, T> ExecutableTxIterator<Evm> for T
|
||||
where
|
||||
Tx: ExecutableTxFor<Evm> + Clone + Send + 'static,
|
||||
Tx: ExecutableTxFor<Evm> + Clone + Send + Sync + 'static,
|
||||
Err: core::error::Error + Send + Sync + 'static,
|
||||
T: Iterator<Item = Result<Tx, Err>> + Send + 'static,
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Traits for execution.
|
||||
|
||||
use crate::{ConfigureEvm, Database, OnStateHook, TxEnvFor};
|
||||
use alloc::{boxed::Box, vec::Vec};
|
||||
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||
use alloy_consensus::{BlockHeader, Header};
|
||||
use alloy_eips::eip2718::WithEncoded;
|
||||
pub use alloy_evm::block::{BlockExecutor, BlockExecutorFactory};
|
||||
@@ -447,7 +447,7 @@ impl<Executor: BlockExecutor> ExecutorTx<Executor> for Recovered<Executor::Trans
|
||||
impl<T, Executor> ExecutorTx<Executor>
|
||||
for WithTxEnv<<<Executor as BlockExecutor>::Evm as Evm>::Tx, T>
|
||||
where
|
||||
T: ExecutorTx<Executor>,
|
||||
T: ExecutorTx<Executor> + Clone,
|
||||
Executor: BlockExecutor,
|
||||
<<Executor as BlockExecutor>::Evm as Evm>::Tx: Clone,
|
||||
Self: RecoveredTx<Executor::Transaction>,
|
||||
@@ -457,7 +457,7 @@ where
|
||||
}
|
||||
|
||||
fn into_recovered(self) -> Recovered<Executor::Transaction> {
|
||||
self.tx.into_recovered()
|
||||
Arc::unwrap_or_clone(self.tx).into_recovered()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -641,7 +641,7 @@ pub struct WithTxEnv<TxEnv, T> {
|
||||
/// The transaction environment for EVM.
|
||||
pub tx_env: TxEnv,
|
||||
/// The recovered transaction.
|
||||
pub tx: T,
|
||||
pub tx: Arc<T>,
|
||||
}
|
||||
|
||||
impl<TxEnv, Tx, T: RecoveredTx<Tx>> RecoveredTx<Tx> for WithTxEnv<TxEnv, T> {
|
||||
|
||||
Reference in New Issue
Block a user