Skip to content

Commit

Permalink
Merge pull request #2449 from ljedrz/perf/dont_allocate_rocksdb_keys
Browse files Browse the repository at this point in the history
[Perf] Don't allocate all rocksdb keys
  • Loading branch information
howardwu committed May 8, 2024
2 parents 8421146 + 7a20bea commit 3ebe60c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion ledger/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ edition = "2021"

[features]
default = [ "indexmap/rayon", "rayon" ]
rocks = [ "once_cell", "rocksdb", "tracing" ]
rocks = [ "once_cell", "rocksdb", "smallvec", "tracing" ]
serial = [
"console/serial",
"ledger-block/serial",
Expand Down Expand Up @@ -117,6 +117,12 @@ version = "1.0"
version = "1.0"
features = [ "preserve_order" ]

[dependencies.smallvec]
version = "1.11"
default-features = false
features = [ "write" ]
optional = true

[dependencies.tracing]
version = "0.1"
optional = true
Expand Down
6 changes: 4 additions & 2 deletions ledger/store/src/helpers/rocksdb/internal/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::helpers::{Map, MapRead};

use core::{fmt, fmt::Debug, hash::Hash, mem};
use indexmap::IndexMap;
use smallvec::SmallVec;
use std::{borrow::Cow, ops::Deref, sync::atomic::Ordering};
use tracing::error;

Expand Down Expand Up @@ -519,12 +520,13 @@ impl<'a, V: 'a + Clone + PartialEq + Eq + Serialize + DeserializeOwned> Iterator

impl<K: Serialize + DeserializeOwned, V: Serialize + DeserializeOwned> DataMap<K, V> {
#[inline]
fn create_prefixed_key<Q>(&self, key: &Q) -> Result<Vec<u8>>
fn create_prefixed_key<Q>(&self, key: &Q) -> Result<SmallVec<[u8; 64]>>
where
K: Borrow<Q>,
Q: Serialize + ?Sized,
{
let mut raw_key = self.context.clone();
let mut raw_key: SmallVec<[u8; 64]> = SmallVec::new();
raw_key.extend_from_slice(&self.context);
bincode::serialize_into(&mut raw_key, &key)?;
Ok(raw_key)
}
Expand Down

0 comments on commit 3ebe60c

Please sign in to comment.