mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
refactor: use Box to store large config objects and add memory usage tests
- Refactored config-related structs to use Box for storing large objects (e.g., IRuntime, IProfiles, PrfItem) to reduce stack memory usage and improve performance. - Updated related methods and assignments to handle Boxed types correctly. - Added and improved unit tests to compare memory usage between Boxed and non-Boxed config objects, demonstrating the memory efficiency of Box. - Test output now shows the size difference between stack-allocated and heap-allocated (Box) config objects.
This commit is contained in:
@@ -22,7 +22,7 @@ pub async fn get_profiles() -> CmdResult<IProfiles> {
|
||||
.await;
|
||||
|
||||
match profiles_result {
|
||||
Ok(Ok(profiles)) => Ok(profiles),
|
||||
Ok(Ok(profiles)) => Ok(*profiles),
|
||||
Ok(Err(join_err)) => {
|
||||
logging!(error, Type::Cmd, true, "获取配置列表任务失败: {}", join_err);
|
||||
Ok(IProfiles {
|
||||
@@ -41,7 +41,7 @@ pub async fn get_profiles() -> CmdResult<IProfiles> {
|
||||
match tokio::task::spawn_blocking(move || Config::profiles().latest().clone()).await {
|
||||
Ok(profiles) => {
|
||||
logging!(info, Type::Cmd, true, "使用latest()成功获取配置");
|
||||
Ok(profiles)
|
||||
Ok(*profiles)
|
||||
}
|
||||
Err(_) => {
|
||||
logging!(error, Type::Cmd, true, "fallback获取配置也失败,返回空配置");
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{config::*, feat, wrap_err};
|
||||
pub fn get_verge_config() -> CmdResult<IVergeResponse> {
|
||||
let verge = Config::verge();
|
||||
let verge_data = verge.data().clone();
|
||||
Ok(IVergeResponse::from(verge_data))
|
||||
Ok(IVergeResponse::from(*verge_data))
|
||||
}
|
||||
|
||||
/// 修改Verge配置
|
||||
|
||||
Reference in New Issue
Block a user