Skip to content

Commit bb62073

Browse files
authored
perf: check prewarm termination multiple times (#19214)
1 parent 0ea75f5 commit bb62073

File tree

1 file changed

+23
-3
lines changed
  • crates/engine/tree/src/tree/payload_processor

1 file changed

+23
-3
lines changed

crates/engine/tree/src/tree/payload_processor/prewarm.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,19 @@ where
233233
});
234234
}
235235

236+
/// Returns true if prewarming was terminated and no more transactions should be prewarmed.
237+
fn is_execution_terminated(&self) -> bool {
238+
self.ctx.terminate_execution.load(Ordering::Relaxed)
239+
}
240+
236241
/// If configured and the tx returned proof targets, emit the targets the transaction produced
237242
fn send_multi_proof_targets(&self, targets: Option<MultiProofTargets>) {
243+
if self.is_execution_terminated() {
244+
// if execution is already terminated then we dont need to send more proof fetch
245+
// messages
246+
return
247+
}
248+
238249
if let Some((proof_targets, to_multi_proof)) = targets.zip(self.to_multi_proof.as_ref()) {
239250
let _ = to_multi_proof.send(MultiProofMessage::PrefetchProofs(proof_targets));
240251
}
@@ -308,6 +319,7 @@ where
308319
match event {
309320
PrewarmTaskEvent::TerminateTransactionExecution => {
310321
// stop tx processing
322+
debug!(target: "engine::tree::prewarm", "Terminating prewarm execution");
311323
self.ctx.terminate_execution.store(true, Ordering::Relaxed);
312324
}
313325
PrewarmTaskEvent::Outcome { proof_targets } => {
@@ -338,7 +350,7 @@ where
338350
}
339351
}
340352

341-
trace!(target: "engine::tree::prewarm", "Completed prewarm execution");
353+
debug!(target: "engine::tree::prewarm", "Completed prewarm execution");
342354

343355
// save caches and finish
344356
if let Some(Some(state)) = final_block_output {
@@ -460,15 +472,16 @@ where
460472
debug_span!(target: "engine::tree::payload_processor::prewarm", "prewarm tx", index, tx_hash=%tx.tx().tx_hash())
461473
.entered();
462474

475+
// create the tx env
476+
let start = Instant::now();
477+
463478
// If the task was cancelled, stop execution, send an empty result to notify the task,
464479
// and exit.
465480
if terminate_execution.load(Ordering::Relaxed) {
466481
let _ = sender.send(PrewarmTaskEvent::Outcome { proof_targets: None });
467482
break
468483
}
469484

470-
// create the tx env
471-
let start = Instant::now();
472485
let res = match evm.transact(&tx) {
473486
Ok(res) => res,
474487
Err(err) => {
@@ -489,6 +502,13 @@ where
489502

490503
drop(_enter);
491504

505+
// If the task was cancelled, stop execution, send an empty result to notify the task,
506+
// and exit.
507+
if terminate_execution.load(Ordering::Relaxed) {
508+
let _ = sender.send(PrewarmTaskEvent::Outcome { proof_targets: None });
509+
break
510+
}
511+
492512
// Only send outcome for transactions after the first txn
493513
// as the main execution will be just as fast
494514
if index > 0 {

0 commit comments

Comments
 (0)