perf(db): use smallvec for mdbx table names (#11291)

This commit is contained in:
DaniPopes
2024-09-27 17:20:43 +02:00
committed by GitHub
parent 0446ec471a
commit 07e94e7fa5
4 changed files with 14 additions and 8 deletions

1
Cargo.lock generated
View File

@ -7544,6 +7544,7 @@ dependencies = [
"rand 0.8.5",
"rand_xorshift",
"reth-mdbx-sys",
"smallvec",
"tempfile",
"thiserror",
"tracing",

View File

@ -12,6 +12,7 @@ cfg_if::cfg_if! {
cfg_if::cfg_if! {
if #[cfg(feature = "tracy-allocator")] {
type AllocatorWrapper = tracy_client::ProfiledAllocator<AllocatorInner>;
tracy_client::register_demangler!();
const fn new_allocator_wrapper() -> AllocatorWrapper {
AllocatorWrapper::new(AllocatorInner {}, 100)
}
@ -23,9 +24,6 @@ cfg_if::cfg_if! {
}
}
#[cfg(feature = "tracy-allocator")]
tracy_client::register_demangler!();
/// Custom allocator.
pub type Allocator = AllocatorWrapper;

View File

@ -19,14 +19,16 @@ byteorder = "1"
derive_more.workspace = true
indexmap = "2"
parking_lot.workspace = true
smallvec.workspace = true
thiserror.workspace = true
dashmap = { workspace = true, features = ["inline"], optional = true }
tracing.workspace = true
dashmap = { workspace = true, features = ["inline"], optional = true }
[features]
default = []
return-borrowed = []
read-tx-timeouts = ["dashmap", "dashmap/inline"]
read-tx-timeouts = ["dep:dashmap"]
[dev-dependencies]
pprof = { workspace = true, features = [

View File

@ -4,7 +4,7 @@ use crate::{
Environment, Transaction,
};
use ffi::MDBX_db_flags_t;
use std::{ffi::CString, ptr};
use std::{ffi::CStr, ptr};
/// A handle to an individual database in an environment.
///
@ -27,8 +27,13 @@ impl Database {
name: Option<&str>,
flags: MDBX_db_flags_t,
) -> Result<Self> {
let c_name = name.map(|n| CString::new(n).unwrap());
let name_ptr = if let Some(c_name) = &c_name { c_name.as_ptr() } else { ptr::null() };
let mut c_name_buf = smallvec::SmallVec::<[u8; 32]>::new();
let c_name = name.map(|n| {
c_name_buf.extend_from_slice(n.as_bytes());
c_name_buf.push(0);
CStr::from_bytes_with_nul(&c_name_buf).unwrap()
});
let name_ptr = if let Some(c_name) = c_name { c_name.as_ptr() } else { ptr::null() };
let mut dbi: ffi::MDBX_dbi = 0;
txn.txn_execute(|txn_ptr| {
mdbx_result(unsafe { ffi::mdbx_dbi_open(txn_ptr, name_ptr, flags, &mut dbi) })