Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

4 changes: 1 addition & 3 deletions crates/cli/util/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -23,9 +24,6 @@ cfg_if::cfg_if! {
}
}

#[cfg(feature = "tracy-allocator")]
tracy_client::register_demangler!();

/// Custom allocator.
pub type Allocator = AllocatorWrapper;

Expand Down
6 changes: 4 additions & 2 deletions crates/storage/libmdbx-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
11 changes: 8 additions & 3 deletions crates/storage/libmdbx-rs/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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) })
Expand Down
Loading