mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-28 09:12:08 +08:00
Every menu API call runs on the main thread; invoked from a worker, each call pays a blocking round-trip there and back (channel, event loop hop, recv). Rebuilding the tray menu with proxy groups enabled issued one round-trip per menu item — 200+ for a typical subscription — and the per-call wait grows whenever the event loop is busy with webview work. Gather the async inputs (verge/clash/profiles snapshots, proxies and runtime group order) on the caller's task, then build the menu and attach it in a single run_on_main_thread closure where every item constructs inline. Measured on a standalone tauri bench (5 groups x 40 nodes): a rebuild drops from ~6.2ms to ~1.6ms on an idle event loop and from ~11.4ms to ~1.6ms with the loop busy (8ms of work per 16ms frame), with ~450 fewer allocations (~155KB) per rebuild.