Skip to content

Commit 43a743f

Browse files
authored
perf(l1): avoid copy when reading account code (#5289)
**Motivation** Currently we use `get_cf` for reading codes, which internally calls `get_pinned_cf` and copies the result.  This copying takes up 6% of code reading time. **Description** Since data needs to be deserialized first, we could use a borrowed value and avoid this copy by calling `get_pinned_cf` directly.
1 parent b31c7a4 commit 43a743f

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 2025-11-12
66

7+
- Avoid copying while reading account code [#5289](https://github.com/lambdaclass/ethrex/pull/5289)
78
- Cache `BLOBBASEFEE` opcode value [#5288](https://github.com/lambdaclass/ethrex/pull/5288)
89

910
### 2025-11-11

crates/storage/store_db/rocksdb.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,11 +1306,14 @@ impl StoreEngine for Store {
13061306
}
13071307

13081308
fn get_account_code(&self, code_hash: H256) -> Result<Option<Code>, StoreError> {
1309-
let hash_key = code_hash.as_bytes().to_vec();
1310-
let Some(bytes) = self.read_sync(CF_ACCOUNT_CODES, hash_key)? else {
1309+
let cf = self.cf_handle(CF_ACCOUNT_CODES)?;
1310+
let Some(bytes) = self
1311+
.db
1312+
.get_pinned_cf(&cf, code_hash.as_bytes())
1313+
.map_err(|e| StoreError::Custom(format!("RocksDB read error: {}", e)))?
1314+
else {
13111315
return Ok(None);
13121316
};
1313-
let bytes = Bytes::from_owner(bytes);
13141317
let (bytecode, targets) = decode_bytes(&bytes)?;
13151318
let code = Code {
13161319
hash: code_hash,

0 commit comments

Comments
 (0)