diff --git a/CHANGELOG.md b/CHANGELOG.md index 2261b9d4534..93f9ffa0c92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Perf +### 2025-11-12 + +- Cache `BLOBBASEFEE` opcode value [#5288](https://github.com/lambdaclass/ethrex/pull/5288) + ### 2025-11-11 - Insert instead of merge for bloom rebuilds [#5223](https://github.com/lambdaclass/ethrex/pull/5223) @@ -17,6 +21,7 @@ - Reuse stack pool in LEVM [#5179](https://github.com/lambdaclass/ethrex/pull/5179) ### 2025-11-05 + - Merkelization backpressure and batching [#5200](https://github.com/lambdaclass/ethrex/pull/5200) ### 2025-11-03 diff --git a/crates/vm/levm/src/opcode_handlers/block.rs b/crates/vm/levm/src/opcode_handlers/block.rs index c91f57ef212..2156ef7c3be 100644 --- a/crates/vm/levm/src/opcode_handlers/block.rs +++ b/crates/vm/levm/src/opcode_handlers/block.rs @@ -166,8 +166,15 @@ impl<'a> VM<'a> { self.current_call_frame .increase_consumed_gas(gas_cost::BLOBBASEFEE)?; - let blob_base_fee = - get_base_fee_per_blob_gas(self.env.block_excess_blob_gas, &self.env.config)?; + let blob_base_fee = match self.blob_base_fee.get() { + Some(value) => *value, + None => { + let value = + get_base_fee_per_blob_gas(self.env.block_excess_blob_gas, &self.env.config)?; + _ = self.blob_base_fee.set(value); + value + } + }; self.current_call_frame.stack.push1(blob_base_fee)?; diff --git a/crates/vm/levm/src/vm.rs b/crates/vm/levm/src/vm.rs index 312014c065e..dfb38081272 100644 --- a/crates/vm/levm/src/vm.rs +++ b/crates/vm/levm/src/vm.rs @@ -23,7 +23,7 @@ use ethrex_common::{ types::{AccessListEntry, Code, Fork, Log, Transaction, fee_config::FeeConfig}, }; use std::{ - cell::RefCell, + cell::{OnceCell, RefCell}, collections::{BTreeMap, BTreeSet, HashMap, HashSet}, mem, rc::Rc, @@ -323,9 +323,12 @@ pub struct VM<'a> { /// A pool of stacks to avoid reallocating too much when creating new call frames. pub stack_pool: Vec, pub vm_type: VMType, + /// The opcode table mapping opcodes to opcode handlers for fast lookup. /// Build dynamically according to the given fork config. pub(crate) opcode_table: [OpCodeFn<'a>; 256], + /// Cached `BLOBBASEFEE` value. + pub(crate) blob_base_fee: OnceCell, } impl<'a> VM<'a> { @@ -375,6 +378,7 @@ impl<'a> VM<'a> { ), env, opcode_table: VM::build_opcode_table(fork), + blob_base_fee: OnceCell::new(), }; let call_type = if is_create {