perf: allocate signer vec exact size (#20638)

This commit is contained in:
Matthias Seitz
2025-12-29 03:18:27 +01:00
committed by GitHub
parent 05b3a8668c
commit 489da4a38b
2 changed files with 16 additions and 1 deletions

View File

@@ -64,6 +64,7 @@ impl EngineApiMetrics {
&self,
executor: E,
mut transactions: impl Iterator<Item = Result<impl ExecutableTx<E>, BlockExecutionError>>,
transaction_count: usize,
state_hook: Box<dyn OnStateHook>,
) -> Result<(BlockExecutionOutput<E::Receipt>, Vec<Address>), BlockExecutionError>
where
@@ -75,7 +76,7 @@ impl EngineApiMetrics {
// be accessible.
let wrapper = MeteredStateHook { metrics: self.executor.clone(), inner_hook: state_hook };
let mut senders = Vec::new();
let mut senders = Vec::with_capacity(transaction_count);
let mut executor = executor.with_state_hook(Some(Box::new(wrapper)));
let f = || {
@@ -529,6 +530,7 @@ mod tests {
let _result = metrics.execute_metered::<_, EmptyDB>(
executor,
input.clone_transactions_recovered().map(Ok::<_, BlockExecutionError>),
input.transaction_count(),
state_hook,
);
@@ -585,6 +587,7 @@ mod tests {
let _result = metrics.execute_metered::<_, EmptyDB>(
executor,
input.clone_transactions_recovered().map(Ok::<_, BlockExecutionError>),
input.transaction_count(),
state_hook,
);

View File

@@ -643,6 +643,7 @@ where
let (output, senders) = self.metrics.execute_metered(
executor,
handle.iter_transactions().map(|res| res.map_err(BlockExecutionError::other)),
input.transaction_count(),
state_hook,
)?;
let execution_finish = Instant::now();
@@ -1291,4 +1292,15 @@ impl<T: PayloadTypes> BlockOrPayload<T> {
// TODO decode and return `BlockAccessList`
None
}
/// Returns the number of transactions in the payload or block.
pub fn transaction_count(&self) -> usize
where
T::ExecutionData: ExecutionPayload,
{
match self {
Self::Payload(payload) => payload.transaction_count(),
Self::Block(block) => block.transaction_count(),
}
}
}