Skip to content

Commit 2f70a77

Browse files
authored
feat: removes the dependency of once_cell (vllm-project#633)
Signed-off-by: htiennv <[email protected]>
1 parent 75e4e66 commit 2f70a77

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

candle-binding/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

candle-binding/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ tracing = "0.1.37"
3636
libc = "0.2.147"
3737
rand = "0.8.5"
3838
# Performance optimization: parallel processing and lock-free initialization
39-
rayon = "1.8"
40-
once_cell = "1.19" # Used for lazy initialization of global state
39+
rayon = "1.8"
4140
parking_lot = "0.12"
4241
crossbeam-channel = "0.5" # Efficient multi-channel select for scheduler wakeup
4342

@@ -56,4 +55,4 @@ path = "../examples/candle-binding/qwen3_example.rs"
5655

5756
# Note: Benchmark binaries are located in ../bench/scripts/rust/candle-binding/
5857
# They are not included in the library build to keep it self-contained.
59-
# To run benchmarks, use the workspace-level Cargo.toml or run them directly from the bench directory.
58+
# To run benchmarks, use the workspace-level Cargo.toml or run them directly from the bench directory.

candle-binding/src/ffi/memory_safety.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
//! including double-free protection, LoRA-specific memory management, and
55
//! path switching safety mechanisms.
66
7-
use once_cell::sync::Lazy;
87
use std::collections::HashMap;
98
use std::ffi::c_char;
10-
use std::sync::{Arc, Mutex, RwLock};
9+
use std::sync::{Arc, LazyLock, Mutex, RwLock};
1110

1211
/// Memory allocation tracking for double-free protection
1312
#[derive(Debug, Clone)]
@@ -48,16 +47,16 @@ pub struct MemorySafetyResult {
4847
pub double_free_attempts: usize,
4948
}
5049

51-
// Global memory tracker for dual-path safety using once_cell::Lazy
50+
// Global memory tracker for dual-path safety using LazyLock
5251
// These are lazily initialized mutable global state for runtime memory tracking
53-
static MEMORY_TRACKER: Lazy<Arc<RwLock<HashMap<usize, AllocationTracker>>>> =
54-
Lazy::new(|| Arc::new(RwLock::new(HashMap::new())));
55-
static DOUBLE_FREE_PROTECTION: Lazy<Arc<Mutex<HashMap<usize, bool>>>> =
56-
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
57-
static LORA_MEMORY_POOL: Lazy<Arc<Mutex<LoRAMemoryPool>>> =
58-
Lazy::new(|| Arc::new(Mutex::new(LoRAMemoryPool::new())));
59-
static PATH_SWITCH_GUARD: Lazy<Arc<RwLock<PathSwitchState>>> =
60-
Lazy::new(|| Arc::new(RwLock::new(PathSwitchState::new())));
52+
static MEMORY_TRACKER: LazyLock<Arc<RwLock<HashMap<usize, AllocationTracker>>>> =
53+
LazyLock::new(|| Arc::new(RwLock::new(HashMap::new())));
54+
static DOUBLE_FREE_PROTECTION: LazyLock<Arc<Mutex<HashMap<usize, bool>>>> =
55+
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
56+
static LORA_MEMORY_POOL: LazyLock<Arc<Mutex<LoRAMemoryPool>>> =
57+
LazyLock::new(|| Arc::new(Mutex::new(LoRAMemoryPool::new())));
58+
static PATH_SWITCH_GUARD: LazyLock<Arc<RwLock<PathSwitchState>>> =
59+
LazyLock::new(|| Arc::new(RwLock::new(PathSwitchState::new())));
6160

6261
/// LoRA-specific memory pool for high-performance allocations
6362
#[derive(Debug)]

candle-binding/src/ffi/state_manager.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Global State Manager
22
3-
use once_cell::sync::Lazy;
43
use std::collections::HashMap;
5-
use std::sync::{Arc, Mutex, RwLock};
4+
use std::sync::{Arc, LazyLock, Mutex, RwLock};
65

76
// Import all necessary types
87
use crate::classifiers::lora::parallel_engine::ParallelLoRAEngine;
@@ -322,8 +321,8 @@ pub struct GlobalStateStats {
322321
pub system_state: SystemState,
323322
}
324323

325-
// Global singleton instance using once_cell::Lazy
326-
static GLOBAL_STATE_MANAGER: Lazy<GlobalStateManager> = Lazy::new(GlobalStateManager::new);
324+
// Global singleton instance using LazyLock
325+
static GLOBAL_STATE_MANAGER: LazyLock<GlobalStateManager> = LazyLock::new(GlobalStateManager::new);
327326

328327
/// Convenience functions for backward compatibility
329328

0 commit comments

Comments
 (0)