mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-01 18:50:04 +08:00
perf(enhance): cut fixed config-generation cost
Every settings toggle reparsed the profile and chain files, ran four Boa interpreters, serialized the runtime config twice, and re-ran mihomo -t over bytes the core had just accepted. Builtin and template scripts now run without Boa, custom scripts bind the config through JSON.parse and take ownership instead of per-script clones, the config serializes once, and mihomo -t is skipped unless the bytes, core build, or geo assets changed. Heavy parses and serializations moved to spawn_blocking. Large-subscription toggles drop from hundreds of milliseconds to ~140ms with no new retained state.
This commit is contained in:
@@ -25,7 +25,6 @@ pub async fn patch_clash(patch: &Mapping) -> Result<()> {
|
||||
if patch.get("mode").is_some() {
|
||||
tray::Tray::global().update_menu_and_icon().await;
|
||||
}
|
||||
Config::runtime().await.edit_draft(|d| d.patch_config(patch));
|
||||
CoreManager::global().update_config_checked().await?;
|
||||
}
|
||||
handle::Handle::refresh_clash();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
config::{
|
||||
Config, ConfigType, MixedPort,
|
||||
Config, MixedPort,
|
||||
snapshot::{FileSnapshot, capture_config_files, restore_files},
|
||||
},
|
||||
core::{
|
||||
@@ -71,8 +71,11 @@ pub async fn save_proxy_ports(settings: ProxyPortSettings) -> Result<SaveProxyPo
|
||||
return Ok(outcome);
|
||||
}
|
||||
|
||||
let yaml = Config::runtime_config_yaml()
|
||||
.await
|
||||
.context("failed to serialize candidate proxy port configuration")?;
|
||||
let validation = CoreConfigValidator::global()
|
||||
.validate_config_outcome()
|
||||
.validate_config_outcome_with(&yaml)
|
||||
.await
|
||||
.context("failed to validate candidate proxy port configuration")?;
|
||||
if !validation.is_valid() {
|
||||
@@ -81,7 +84,7 @@ pub async fn save_proxy_ports(settings: ProxyPortSettings) -> Result<SaveProxyPo
|
||||
|
||||
let snapshots = capture_config_files().await?;
|
||||
// Once files change, failures must restore both files and drafts.
|
||||
if let Err(error) = Config::generate_file(ConfigType::Run).await {
|
||||
if let Err(error) = Config::write_runtime_file(&yaml).await {
|
||||
transaction.rollback();
|
||||
return match restore_files(&snapshots).await {
|
||||
Ok(()) => Err(error).context("failed to persist candidate Runtime Configuration"),
|
||||
@@ -232,7 +235,7 @@ async fn rollback_proxy_ports(snapshots: &[FileSnapshot], was_running: bool) ->
|
||||
discard_proxy_port_drafts().await;
|
||||
let file_result = restore_files(snapshots).await;
|
||||
if file_result.is_err() {
|
||||
let _ = Config::generate_file(ConfigType::Run).await;
|
||||
let _ = Config::generate_file().await;
|
||||
}
|
||||
|
||||
let lifecycle_result = if was_running {
|
||||
|
||||
Reference in New Issue
Block a user