perf(trie): add inline hints to database cursor methods

Add #[inline] to frequently-called cursor methods in trie traversal hot paths.
This commit is contained in:
yongkangc
2026-01-03 07:17:25 +00:00
parent 3d4efdb271
commit c5c1845a0b
2 changed files with 16 additions and 0 deletions

View File

@@ -62,14 +62,17 @@ where
{ {
type Value = Account; type Value = Account;
#[inline]
fn seek(&mut self, key: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError> { fn seek(&mut self, key: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
self.0.seek(key) self.0.seek(key)
} }
#[inline]
fn next(&mut self) -> Result<Option<(B256, Self::Value)>, DatabaseError> { fn next(&mut self) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
self.0.next() self.0.next()
} }
#[inline]
fn reset(&mut self) { fn reset(&mut self) {
// Database cursors are stateless, no reset needed // Database cursors are stateless, no reset needed
} }
@@ -99,14 +102,17 @@ where
{ {
type Value = U256; type Value = U256;
#[inline]
fn seek(&mut self, subkey: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError> { fn seek(&mut self, subkey: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
Ok(self.cursor.seek_by_key_subkey(self.hashed_address, subkey)?.map(|e| (e.key, e.value))) Ok(self.cursor.seek_by_key_subkey(self.hashed_address, subkey)?.map(|e| (e.key, e.value)))
} }
#[inline]
fn next(&mut self) -> Result<Option<(B256, Self::Value)>, DatabaseError> { fn next(&mut self) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
Ok(self.cursor.next_dup_val()?.map(|e| (e.key, e.value))) Ok(self.cursor.next_dup_val()?.map(|e| (e.key, e.value)))
} }
#[inline]
fn reset(&mut self) { fn reset(&mut self) {
// Database cursors are stateless, no reset needed // Database cursors are stateless, no reset needed
} }

View File

@@ -67,6 +67,7 @@ where
C: DbCursorRO<tables::AccountsTrie> + Send + Sync, C: DbCursorRO<tables::AccountsTrie> + Send + Sync,
{ {
/// Seeks an exact match for the provided key in the account trie. /// Seeks an exact match for the provided key in the account trie.
#[inline]
fn seek_exact( fn seek_exact(
&mut self, &mut self,
key: Nibbles, key: Nibbles,
@@ -75,6 +76,7 @@ where
} }
/// Seeks a key in the account trie that matches or is greater than the provided key. /// Seeks a key in the account trie that matches or is greater than the provided key.
#[inline]
fn seek( fn seek(
&mut self, &mut self,
key: Nibbles, key: Nibbles,
@@ -83,15 +85,18 @@ where
} }
/// Move the cursor to the next entry and return it. /// Move the cursor to the next entry and return it.
#[inline]
fn next(&mut self) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError> { fn next(&mut self) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError> {
Ok(self.0.next()?.map(|value| (value.0 .0, value.1))) Ok(self.0.next()?.map(|value| (value.0 .0, value.1)))
} }
/// Retrieves the current key in the cursor. /// Retrieves the current key in the cursor.
#[inline]
fn current(&mut self) -> Result<Option<Nibbles>, DatabaseError> { fn current(&mut self) -> Result<Option<Nibbles>, DatabaseError> {
Ok(self.0.current()?.map(|(k, _)| k.0)) Ok(self.0.current()?.map(|(k, _)| k.0))
} }
#[inline]
fn reset(&mut self) { fn reset(&mut self) {
// No-op for database cursors // No-op for database cursors
} }
@@ -163,6 +168,7 @@ where
C: DbCursorRO<tables::StoragesTrie> + DbDupCursorRO<tables::StoragesTrie> + Send + Sync, C: DbCursorRO<tables::StoragesTrie> + DbDupCursorRO<tables::StoragesTrie> + Send + Sync,
{ {
/// Seeks an exact match for the given key in the storage trie. /// Seeks an exact match for the given key in the storage trie.
#[inline]
fn seek_exact( fn seek_exact(
&mut self, &mut self,
key: Nibbles, key: Nibbles,
@@ -175,6 +181,7 @@ where
} }
/// Seeks the given key in the storage trie. /// Seeks the given key in the storage trie.
#[inline]
fn seek( fn seek(
&mut self, &mut self,
key: Nibbles, key: Nibbles,
@@ -186,15 +193,18 @@ where
} }
/// Move the cursor to the next entry and return it. /// Move the cursor to the next entry and return it.
#[inline]
fn next(&mut self) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError> { fn next(&mut self) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError> {
Ok(self.cursor.next_dup()?.map(|(_, v)| (v.nibbles.0, v.node))) Ok(self.cursor.next_dup()?.map(|(_, v)| (v.nibbles.0, v.node)))
} }
/// Retrieves the current value in the storage trie cursor. /// Retrieves the current value in the storage trie cursor.
#[inline]
fn current(&mut self) -> Result<Option<Nibbles>, DatabaseError> { fn current(&mut self) -> Result<Option<Nibbles>, DatabaseError> {
Ok(self.cursor.current()?.map(|(_, v)| v.nibbles.0)) Ok(self.cursor.current()?.map(|(_, v)| v.nibbles.0))
} }
#[inline]
fn reset(&mut self) { fn reset(&mut self) {
// No-op for database cursors // No-op for database cursors
} }