perf: cut the boot and poll overhead (one settings fetch, one git process per tick, one fold per poll)

Boot: loadPrefs and loadExternalDisable each fetched the settings
document, serially, before the first paint — and the second had no
timeout, so a stalled wire kept the sidebar unmounted forever. Both
decisions now ride ONE fetch (loadBootDecision) under the existing
2s race.

GitLens: the 2s silent poll re-listed worktrees on every tick (a
second git process per tick for a list that almost never changes, and
a fresh worktrees array re-render each time). Silent ticks now fetch
only the selected checkout's status; every 15th tick (~30s) re-lists
and re-runs auto-selection, so an agent-created linked checkout is
still picked up mid-session.

ChangesTab: extractFileOps parses every accumulated tool/call (up to
4000 events); the poll ran it once for the badge and the render ran
it AGAIN per tick, and the fresh array defeated the downstream memo.
The fold now runs once per poll and its result rides a ref shared by
badge and render (reset on session switch).
This commit is contained in:
Menghuan1918
2026-09-01 15:58:44 +08:00
parent e2699a099e
commit 427552e4f9
5 changed files with 93 additions and 19 deletions
+19
View File
@@ -217,3 +217,22 @@ export async function loadExternalDisable(settings: SidebarSettingsClient): Prom
return false
}
}
/** The boot decision both the prefs and the external-disable flag need:
* ONE settings fetch answers both (the boot path used to await
* {@link loadPrefs} and {@link loadExternalDisable} serially — two round
* trips of the same document before the first paint, and the second had no
* timeout, so a stalled wire could keep the sidebar unmounted forever). */
export interface BootDecision {
prefs: SidebarPrefs
suspended: boolean
}
export async function loadBootDecision(settings: SidebarSettingsClient): Promise<BootDecision> {
try {
const view = await settings.settingsGet()
return { prefs: parsePrefs(view.value), suspended: view.externalDisable === true }
} catch {
return { prefs: { ...SIDEBAR_PREFS_DEFAULTS }, suspended: false }
}
}