perf(backend): trim redundant copies on service IPC paths (#8720)

* perf(core): remove redundant copies on service IPC paths

Allocation and copy trims on the service IPC hot paths; the wire format
is untouched:

- store the owner session proof as Arc: active_service_session()
  retrieval becomes a refcount clone instead of a 64-char string copy
  per call (~12 call sites, including the frontend-polled log path).
  The one external caller takes Proof: Borrow<OwnerSessionProof> so its
  four test closures stay unchanged.
- build the session token hex with one allocation instead of 32
  format! allocations plus Vec growth (35 -> 1 allocations measured),
  mirroring owner_identity::encode_token.
- reuse one RuntimeFileRequest across the provider cache-sync chunk
  loop; only .offset changes per chunk.
- move the proposed session token out of StartClashRequest on success
  instead of cloning it up-front.
- report the non-actionable service status by reference before
  set_status takes ownership.
- hoist the macOS install markers to LazyLock, pass osascript args as
  an array, compare the install-wait core name via the requirement
  array, and log the silent-updater version by reference.

* fix(core): gate the LazyLock import to macOS

The install-marker static is the only LazyLock user in the module and
is macOS-gated; the ungated import made clippy -D warnings fail the
Linux and Windows builds. Co-locate the import with its cfg.
This commit is contained in:
Tunglies
2026-11-23 09:11:58 +00:00
committed by GitHub
parent 08d09cc5f3
commit a85640a571
4 changed files with 58 additions and 41 deletions
+5 -3
View File
@@ -19,6 +19,7 @@ use anyhow::{Result, ensure};
use clash_verge_logging::{Type, logging};
use clash_verge_service_ipc::{MacosProxyConfig, OwnerSessionProof, ProxyApplyOutcome};
use std::{
borrow::Borrow,
future::Future,
sync::atomic::{AtomicU64, Ordering},
time::Duration,
@@ -271,7 +272,7 @@ impl ServiceProxyOperations {
.await
}
async fn run_guard_request<Mode, ActiveProof, Request, RequestFuture>(
async fn run_guard_request<Mode, ActiveProof, Proof, Request, RequestFuture>(
&self,
captured_generation: u64,
captured_proof: &OwnerSessionProof,
@@ -282,14 +283,15 @@ impl ServiceProxyOperations {
) -> Result<bool>
where
Mode: FnOnce() -> bool,
ActiveProof: FnOnce() -> Result<OwnerSessionProof>,
ActiveProof: FnOnce() -> Result<Proof>,
Proof: Borrow<OwnerSessionProof>,
Request: FnOnce() -> RequestFuture,
RequestFuture: Future<Output = Result<ProxyApplyOutcome>>,
{
self.run_service_operation(|| async move {
if !guard_generation_is_current(&self.guard_generation, captured_generation)
|| !is_service_mode()
|| !active_proof().is_ok_and(|active| active == *captured_proof)
|| !active_proof().is_ok_and(|active| active.borrow() == captured_proof)
{
return Ok(false);
}