perf: batch byte for serialization (#19096)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
malik
2025-10-20 16:04:31 +01:00
committed by GitHub
parent be2306da31
commit e198a38d62
5 changed files with 18 additions and 14 deletions

1
Cargo.lock generated
View File

@@ -10683,6 +10683,7 @@ dependencies = [
"alloy-serde",
"alloy-trie",
"arbitrary",
"arrayvec",
"bincode 1.3.3",
"bytes",
"codspeed-criterion-compat",

View File

@@ -534,6 +534,7 @@ op-alloy-flz = { version = "0.13.1", default-features = false }
# misc
either = { version = "1.15.0", default-features = false }
arrayvec = { version = "0.7.6", default-features = false }
aquamarine = "0.6"
auto_impl = "1"
backon = { version = "1.2", default-features = false, features = ["std-blocking-sleep", "tokio-sleep"] }

View File

@@ -23,6 +23,7 @@ reth-codecs = { workspace = true, optional = true }
alloy-rpc-types-eth = { workspace = true, optional = true }
alloy-serde = { workspace = true, optional = true }
arrayvec = { workspace = true, optional = true }
bytes = { workspace = true, optional = true }
derive_more.workspace = true
itertools = { workspace = true, features = ["use_alloc"] }
@@ -83,10 +84,12 @@ std = [
"serde_json/std",
"revm-database/std",
"revm-state/std",
"arrayvec?/std",
]
eip1186 = ["alloy-rpc-types-eth/serde", "dep:alloy-serde"]
serde = [
"dep:serde",
"arrayvec?/serde",
"bytes?/serde",
"nybbles/serde",
"alloy-primitives/serde",
@@ -98,7 +101,7 @@ serde = [
"revm-database/serde",
"revm-state/serde",
]
reth-codec = ["dep:reth-codecs", "dep:bytes"]
reth-codec = ["dep:reth-codecs", "dep:bytes", "dep:arrayvec"]
serde-bincode-compat = [
"serde",
"reth-primitives-traits/serde-bincode-compat",

View File

@@ -28,10 +28,9 @@ impl reth_codecs::Compact for StoredNibbles {
where
B: bytes::BufMut + AsMut<[u8]>,
{
for i in self.0.iter() {
buf.put_u8(i);
}
self.0.len()
let bytes = self.0.iter().collect::<arrayvec::ArrayVec<u8, 64>>();
buf.put_slice(&bytes);
bytes.len()
}
fn from_compact(mut buf: &[u8], len: usize) -> (Self, &[u8]) {
@@ -78,14 +77,14 @@ impl reth_codecs::Compact for StoredNibblesSubKey {
{
assert!(self.0.len() <= 64);
// right-pad with zeros
for i in self.0.iter() {
buf.put_u8(i);
}
static ZERO: &[u8; 64] = &[0; 64];
buf.put_slice(&ZERO[self.0.len()..]);
let bytes = self.0.iter().collect::<arrayvec::ArrayVec<u8, 64>>();
buf.put_slice(&bytes);
buf.put_u8(self.0.len() as u8);
// Right-pad with zeros
static ZERO: &[u8; 64] = &[0; 64];
buf.put_slice(&ZERO[bytes.len()..]);
buf.put_u8(bytes.len() as u8);
64 + 1
}

View File

@@ -1,4 +1,4 @@
use super::{BranchNodeCompact, Nibbles, StoredNibblesSubKey};
use super::{BranchNodeCompact, StoredNibblesSubKey};
/// Account storage trie node.
///
@@ -61,7 +61,7 @@ impl reth_codecs::Compact for TrieChangeSetsEntry {
if len == 0 {
// Return an empty entry without trying to parse anything
return (
Self { nibbles: StoredNibblesSubKey::from(Nibbles::default()), node: None },
Self { nibbles: StoredNibblesSubKey::from(super::Nibbles::default()), node: None },
buf,
)
}