core: skip network-stack rebuild when SetNetworkMode is a no-op
The GUI re-sends the saved network mode as part of its startup config-sync. The SetNetworkMode handler unconditionally tore down + rebuilt the iroh endpoint whenever idle, so every launch rebuilt the freshly-built stack for an identical posture — a needless ~1s teardown+rebuild bounce visible in the logs on both Linux and Windows/Wine (the 'start core loop -> shut down network stack ~1s later' pattern from the Wine spike). Guard the rebuild on an actual mode change; a real change still rebuilds exactly as before. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+20
-11
@@ -1816,17 +1816,26 @@ async fn run_core_loop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoreCommand::SetNetworkMode(mode) => {
|
CoreCommand::SetNetworkMode(mode) => {
|
||||||
network_mode = mode;
|
// Skip when the posture is unchanged. The GUI re-sends the saved
|
||||||
// Rebuild the persistent stack to the new posture immediately if
|
// network mode as part of its startup config-sync, and that mode
|
||||||
// idle; if a call is active, defer to the next Leave/Join so the
|
// usually already matches the freshly-built stack — rebuilding the
|
||||||
// live call isn't disrupted (preserves "applies on next join").
|
// iroh endpoint for an identical posture just churns the network
|
||||||
if active_session.is_none() {
|
// and adds a needless ~1s teardown+rebuild bounce at every launch
|
||||||
let lookup = net.memory_lookup.clone();
|
// (seen on both Linux and Windows/Wine). A real change still
|
||||||
net.shutdown().await;
|
// rebuilds exactly as before.
|
||||||
let publish = presence_mode.lock().unwrap().publishes_to_discovery();
|
if mode != network_mode {
|
||||||
net = build_net_stack(secret_key.clone(), network_mode, lookup, friends_handler.clone(), publish).await?;
|
network_mode = mode;
|
||||||
} else {
|
// Rebuild the persistent stack to the new posture immediately if
|
||||||
net_rebuild_pending = true;
|
// idle; if a call is active, defer to the next Leave/Join so the
|
||||||
|
// live call isn't disrupted (preserves "applies on next join").
|
||||||
|
if active_session.is_none() {
|
||||||
|
let lookup = net.memory_lookup.clone();
|
||||||
|
net.shutdown().await;
|
||||||
|
let publish = presence_mode.lock().unwrap().publishes_to_discovery();
|
||||||
|
net = build_net_stack(secret_key.clone(), network_mode, lookup, friends_handler.clone(), publish).await?;
|
||||||
|
} else {
|
||||||
|
net_rebuild_pending = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user