From c5c1845a0b6ca0f33a31eb3c666b85dcd3b8e94e Mon Sep 17 00:00:00 2001 From: yongkangc Date: Sat, 3 Jan 2026 07:17:25 +0000 Subject: [PATCH] perf(trie): add inline hints to database cursor methods Add #[inline] to frequently-called cursor methods in trie traversal hot paths. --- crates/trie/db/src/hashed_cursor.rs | 6 ++++++ crates/trie/db/src/trie_cursor.rs | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/crates/trie/db/src/hashed_cursor.rs b/crates/trie/db/src/hashed_cursor.rs index 10a1fd8363..832b46c8dc 100644 --- a/crates/trie/db/src/hashed_cursor.rs +++ b/crates/trie/db/src/hashed_cursor.rs @@ -62,14 +62,17 @@ where { type Value = Account; + #[inline] fn seek(&mut self, key: B256) -> Result, DatabaseError> { self.0.seek(key) } + #[inline] fn next(&mut self) -> Result, DatabaseError> { self.0.next() } + #[inline] fn reset(&mut self) { // Database cursors are stateless, no reset needed } @@ -99,14 +102,17 @@ where { type Value = U256; + #[inline] fn seek(&mut self, subkey: B256) -> Result, DatabaseError> { Ok(self.cursor.seek_by_key_subkey(self.hashed_address, subkey)?.map(|e| (e.key, e.value))) } + #[inline] fn next(&mut self) -> Result, DatabaseError> { Ok(self.cursor.next_dup_val()?.map(|e| (e.key, e.value))) } + #[inline] fn reset(&mut self) { // Database cursors are stateless, no reset needed } diff --git a/crates/trie/db/src/trie_cursor.rs b/crates/trie/db/src/trie_cursor.rs index 7b9c402545..bb69d4638d 100644 --- a/crates/trie/db/src/trie_cursor.rs +++ b/crates/trie/db/src/trie_cursor.rs @@ -67,6 +67,7 @@ where C: DbCursorRO + Send + Sync, { /// Seeks an exact match for the provided key in the account trie. + #[inline] fn seek_exact( &mut self, key: Nibbles, @@ -75,6 +76,7 @@ where } /// Seeks a key in the account trie that matches or is greater than the provided key. + #[inline] fn seek( &mut self, key: Nibbles, @@ -83,15 +85,18 @@ where } /// Move the cursor to the next entry and return it. + #[inline] fn next(&mut self) -> Result, DatabaseError> { Ok(self.0.next()?.map(|value| (value.0 .0, value.1))) } /// Retrieves the current key in the cursor. + #[inline] fn current(&mut self) -> Result, DatabaseError> { Ok(self.0.current()?.map(|(k, _)| k.0)) } + #[inline] fn reset(&mut self) { // No-op for database cursors } @@ -163,6 +168,7 @@ where C: DbCursorRO + DbDupCursorRO + Send + Sync, { /// Seeks an exact match for the given key in the storage trie. + #[inline] fn seek_exact( &mut self, key: Nibbles, @@ -175,6 +181,7 @@ where } /// Seeks the given key in the storage trie. + #[inline] fn seek( &mut self, key: Nibbles, @@ -186,15 +193,18 @@ where } /// Move the cursor to the next entry and return it. + #[inline] fn next(&mut self) -> Result, DatabaseError> { Ok(self.cursor.next_dup()?.map(|(_, v)| (v.nibbles.0, v.node))) } /// Retrieves the current value in the storage trie cursor. + #[inline] fn current(&mut self) -> Result, DatabaseError> { Ok(self.cursor.current()?.map(|(_, v)| v.nibbles.0)) } + #[inline] fn reset(&mut self) { // No-op for database cursors }