mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-22 20:32:15 +08:00
perf(backend): cut redundant copies and rebuilds in enhance, config and tray paths (#8666)
* fix: mechanical string conversions - &String parameters become &str (event payload fields borrow &str; wire format unchanged) - Cow/std-string double conversions collapse to a single Into - sha256 digests format through a shared hex lookup table instead of one format! allocation per byte - i18n placeholder replacement only allocates when the placeholder exists * perf(enhance): marshal scripts by value and diff fields by fingerprint - scripts cross into boa via JsValue::from_json/to_json instead of the JSON text round-trip (config clone + json string + UTF-16 JsString + stringify + re-parse all disappear); size guards use an allocation-free approximate walk - merge documents and tun/dns patches move values instead of deep-cloning whole sub-trees per pass - authoritative-field snapshots hash dns/hosts/tun values instead of cloning them around every chain item (9 snapshots per enhance) - proxy-name cleanup sets build from &str in one conversion * perf(config): write yaml headers in place and record selections without copying - save_yaml_str takes an optional header prefix written as separate chunks, so the MB-scale serialized payload is never duplicated by format! just to prepend a comment (profiles/verge/clash/runtime yaml all benefit; file bytes unchanged) - the runtime yaml string no longer round-trips through a prefixed copy; write_runtime_file adds the header when persisting - record/forget selected nodes mutate the stored selection list in place instead of cloning it per click * perf(tray): drop the redundant full rebuild in update_part update_part rebuilt the menu twice back to back: once without proxy groups, then a spawned full update_menu. Keep the partial rebuild only.
This commit is contained in:
@@ -216,7 +216,7 @@ impl Config {
|
||||
.or_else(|| runtime_data.config.as_ref())
|
||||
.ok_or_else(|| anyhow!("failed to generate runtime config, might need to restart application"))?;
|
||||
let yaml_str = serde_yaml_ng::to_string(config)?;
|
||||
Ok(format!("# Generated by Clash Verge\n\n{}", yaml_str))
|
||||
Ok(yaml_str)
|
||||
})
|
||||
.await
|
||||
.map_err(|join| anyhow!("runtime serialization task failed: {join}"))?
|
||||
@@ -224,7 +224,7 @@ impl Config {
|
||||
|
||||
pub(crate) async fn write_runtime_file(yaml: &str) -> Result<PathBuf> {
|
||||
let path = dirs::app_home_dir()?.join(files::RUNTIME_CONFIG);
|
||||
help::save_yaml_str(&path, yaml).await?;
|
||||
help::save_yaml_str(&path, yaml, Some("# Generated by Clash Verge")).await?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user