reth_cli_util/
allocator.rs

1//! Custom allocator implementation.
2
3// We use jemalloc for performance reasons.
4cfg_if::cfg_if! {
5    if #[cfg(all(feature = "jemalloc", unix))] {
6        type AllocatorInner = tikv_jemallocator::Jemalloc;
7    } else {
8        type AllocatorInner = std::alloc::System;
9    }
10}
11
12cfg_if::cfg_if! {
13    if #[cfg(feature = "tracy-allocator")] {
14        type AllocatorWrapper = tracy_client::ProfiledAllocator<AllocatorInner>;
15        tracy_client::register_demangler!();
16        const fn new_allocator_wrapper() -> AllocatorWrapper {
17            AllocatorWrapper::new(AllocatorInner {}, 100)
18        }
19    } else {
20        type AllocatorWrapper = AllocatorInner;
21        const fn new_allocator_wrapper() -> AllocatorWrapper {
22            AllocatorInner {}
23        }
24    }
25}
26
27/// Custom allocator.
28pub type Allocator = AllocatorWrapper;
29
30/// Creates a new [custom allocator][Allocator].
31pub const fn new_allocator() -> Allocator {
32    new_allocator_wrapper()
33}