pub mod advanced_networking;
pub mod arena_allocator;
pub mod io_optimizations;
pub mod lockfree_storage;
pub mod memory;
pub mod mmap_storage;
pub mod network_simple;
pub mod object_pool;
pub mod quick_wins;
pub mod simd_optimizations;
pub mod smart_pointers;
pub mod ultra_performance;
pub mod zero_copy_storage; pub mod custom_allocator;
pub mod numa_allocator;
pub mod thread_affinity;
pub mod consumer_arena;
pub mod protocol_arena;
use std::sync::atomic::{AtomicUsize, Ordering};
pub struct PerformanceMetrics {
pub allocations: AtomicUsize,
pub deallocations: AtomicUsize,
pub arc_clones: AtomicUsize,
pub cache_hits: AtomicUsize,
pub cache_misses: AtomicUsize,
}
impl PerformanceMetrics {
pub fn new() -> Self {
Self {
allocations: AtomicUsize::new(0),
deallocations: AtomicUsize::new(0),
arc_clones: AtomicUsize::new(0),
cache_hits: AtomicUsize::new(0),
cache_misses: AtomicUsize::new(0),
}
}
pub fn record_allocation(&self) {
self.allocations.fetch_add(1, Ordering::Relaxed);
}
pub fn record_deallocation(&self) {
self.deallocations.fetch_add(1, Ordering::Relaxed);
}
pub fn record_arc_clone(&self) {
self.arc_clones.fetch_add(1, Ordering::Relaxed);
}
pub fn record_cache_hit(&self) {
self.cache_hits.fetch_add(1, Ordering::Relaxed);
}
pub fn record_cache_miss(&self) {
self.cache_misses.fetch_add(1, Ordering::Relaxed);
}
pub fn get_stats(&self) -> PerformanceStats {
PerformanceStats {
allocations: self.allocations.load(Ordering::Relaxed),
deallocations: self.deallocations.load(Ordering::Relaxed),
arc_clones: self.arc_clones.load(Ordering::Relaxed),
cache_hits: self.cache_hits.load(Ordering::Relaxed),
cache_misses: self.cache_misses.load(Ordering::Relaxed),
}
}
}
#[derive(Debug, Clone)]
pub struct PerformanceStats {
pub allocations: usize,
pub deallocations: usize,
pub arc_clones: usize,
pub cache_hits: usize,
pub cache_misses: usize,
}
impl PerformanceStats {
pub fn cache_hit_ratio(&self) -> f64 {
let total = self.cache_hits + self.cache_misses;
if total == 0 {
0.0
} else {
self.cache_hits as f64 / total as f64
}
}
pub fn memory_efficiency(&self) -> f64 {
if self.allocations == 0 {
1.0
} else {
self.deallocations as f64 / self.allocations as f64
}
}
}