refactor: modernize dependency stack and minimize footprint

- Migrate to native 'std::sync' primitives (LazyLock, OnceLock, RwLock).
- Replace 'parking_lot' with std library synchronization types.
- Switch from 'chrono' to 'std::time::SystemTime' for lightweight timestamps.
- Bump core dependencies: tokio (1.50.0) and rustls (0.23.37).
- Decouple 'solana-program' by utilizing 'solana-sdk' re-exports.
- Prune redundant crates: lazy_static, once_cell, chrono, maplit, and parking_lot.
- Remove unused dev-dependencies (criterion) and example-only utils (env_logger).
- Improve compile times and reduce supply chain attack surface.
This commit is contained in:
Estereg
2026-03-07 06:44:42 +00:00
parent 7270372604
commit 0c369e23a8
12 changed files with 42 additions and 52 deletions
@@ -179,8 +179,8 @@ impl Default for GlobalState {
}
/// Global state instance
static GLOBAL_STATE: once_cell::sync::Lazy<GlobalState> =
once_cell::sync::Lazy::new(GlobalState::new);
static GLOBAL_STATE: std::sync::LazyLock<GlobalState> =
std::sync::LazyLock::new(GlobalState::new);
/// Get global state instance
pub fn get_global_state() -> &'static GlobalState {
@@ -54,8 +54,8 @@ impl CacheKey {
/// 全局程序ID缓存(使用读写锁保护)
static GLOBAL_PROGRAM_IDS_CACHE: LazyLock<
parking_lot::RwLock<HashMap<CacheKey, Arc<Vec<Pubkey>>>>,
> = LazyLock::new(|| parking_lot::RwLock::new(HashMap::new()));
std::sync::RwLock<HashMap<CacheKey, Arc<Vec<Pubkey>>>>,
> = LazyLock::new(|| std::sync::RwLock::new(HashMap::new()));
/// 获取指定协议的程序ID列表
///
@@ -68,7 +68,7 @@ pub fn get_global_program_ids(
// 快速路径:尝试读取缓存
{
let cache = GLOBAL_PROGRAM_IDS_CACHE.read();
let cache = GLOBAL_PROGRAM_IDS_CACHE.read().unwrap();
if let Some(program_ids) = cache.get(&cache_key) {
return program_ids.clone();
}
@@ -78,7 +78,7 @@ pub fn get_global_program_ids(
let program_ids = Arc::new(EventDispatcher::get_program_ids(protocols));
// 缓存结果(写锁)
GLOBAL_PROGRAM_IDS_CACHE.write().insert(cache_key, program_ids.clone());
GLOBAL_PROGRAM_IDS_CACHE.write().unwrap().insert(cache_key, program_ids.clone());
program_ids
}