diff --git a/UPDATELOG.md b/UPDATELOG.md index 492d4fee8..dcd1188f1 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -6,7 +6,7 @@ ### 🚀 性能优化 -- 优化节点信息缓存占用 +- 优化内存占用 ### 🐞 修复问题 @@ -15,7 +15,7 @@ - 修复2.4.1引入的订阅地址重定向报错问题 - 修复 rpm/deb 包名称问题 - 修复托盘轻量模式状态检测异常 -- 修复通过 scheme 导入订阅奔溃 +- 修复通过 scheme 导入订阅崩溃 - 修复单例检测实效 ### 👙 界面样式 diff --git a/src-tauri/src/ipc/general.rs b/src-tauri/src/ipc/general.rs index adbfbf8e8..d2d3f7c2e 100644 --- a/src-tauri/src/ipc/general.rs +++ b/src-tauri/src/ipc/general.rs @@ -24,8 +24,7 @@ fn create_error(msg: impl Into) -> AnyError { } pub struct IpcManager { - ipc_path: String, - config: ClientConfig, + client: IpcHttpClient, } impl IpcManager { @@ -41,25 +40,25 @@ impl IpcManager { std::path::PathBuf::from("/tmp/clash-verge-ipc") // fallback path }); let ipc_path = ipc_path_buf.to_str().unwrap_or_default(); - Self { - ipc_path: ipc_path.to_string(), - config: ClientConfig { - default_timeout: Duration::from_secs(5), - enable_pooling: true, + let config = ClientConfig { + default_timeout: Duration::from_secs(5), + enable_pooling: true, + max_retries: 3, + max_concurrent_requests: 64, + max_requests_per_second: Some(10.0), + pool_config: PoolConfig { + max_size: 64, + min_idle: 8, + max_idle_time_ms: 60_000, max_retries: 3, - max_concurrent_requests: 32, - max_requests_per_second: Some(5.0), - pool_config: PoolConfig { - max_size: 32, - min_idle: 2, - max_idle_time_ms: 10_000, - max_retries: 3, - max_concurrent_requests: 32, - max_requests_per_second: Some(5.0), - ..Default::default() - }, + max_concurrent_requests: 64, + max_requests_per_second: Some(10.0), ..Default::default() }, + ..Default::default() + }; + Self { + client: IpcHttpClient::with_config(ipc_path, config).unwrap(), } } } @@ -74,8 +73,7 @@ impl IpcManager { path: &str, body: Option<&serde_json::Value>, ) -> AnyResult { - let client = IpcHttpClient::with_config(&self.ipc_path, self.config.clone())?; - client.request(method, path, body).await + self.client.request(method, path, body).await } } diff --git a/src-tauri/src/module/lightweight.rs b/src-tauri/src/module/lightweight.rs index 0fc1e58f4..c8e08d6cd 100644 --- a/src-tauri/src/module/lightweight.rs +++ b/src-tauri/src/module/lightweight.rs @@ -3,6 +3,7 @@ use crate::{ core::{handle, timer::Timer, tray::Tray}, log_err, logging, process::AsyncHandler, + state::proxy::ProxyRequestCache, utils::{logging::Type, window_manager::WindowManager}, }; @@ -153,6 +154,7 @@ pub async fn entry_lightweight_mode() { } set_lightweight_mode(true).await; let _ = cancel_light_weight_timer(); + ProxyRequestCache::global().clean_default_keys(); // 更新托盘显示 logging_error!(Type::Lightweight, true, Tray::global().update_part().await); diff --git a/src-tauri/src/state/proxy.rs b/src-tauri/src/state/proxy.rs index 197ec81fb..c0c139b35 100644 --- a/src-tauri/src/state/proxy.rs +++ b/src-tauri/src/state/proxy.rs @@ -1,3 +1,5 @@ +// use crate::utils::logging::Type; +// use crate::{logging, singleton}; use crate::singleton; use dashmap::DashMap; use serde_json::Value; @@ -78,6 +80,22 @@ impl ProxyRequestCache { } } } + + // TODO + pub fn clean_default_keys(&self) { + // logging!(info, Type::Cache, "Cleaning proxies keys"); + // let proxies_key = Self::make_key("proxies", "default"); + // self.map.remove(&proxies_key); + + // logging!(info, Type::Cache, "Cleaning providers keys"); + // let providers_key = Self::make_key("providers", "default"); + // self.map.remove(&providers_key); + + // !The frontend goes crash if we clean the clash_config cache + // logging!(info, Type::Cache, "Cleaning clash config keys"); + // let clash_config_key = Self::make_key("clash_config", "default"); + // self.map.remove(&clash_config_key); + } } // Use singleton macro diff --git a/src-tauri/src/utils/logging.rs b/src-tauri/src/utils/logging.rs index 62c8e5a8e..6762ddb92 100644 --- a/src-tauri/src/utils/logging.rs +++ b/src-tauri/src/utils/logging.rs @@ -18,6 +18,7 @@ pub enum Type { Network, ProxyMode, Ipc, + // Cache, } impl fmt::Display for Type { @@ -39,6 +40,7 @@ impl fmt::Display for Type { Type::Network => write!(f, "[Network]"), Type::ProxyMode => write!(f, "[ProxMode]"), Type::Ipc => write!(f, "[IPC]"), + // Type::Cache => write!(f, "[Cache]"), } } }