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:
+26
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { loadExternalDisable, loadPrefs, type SidebarSettingsClient } from '../src/client/prefs.ts'
|
||||
import { loadBootDecision, loadExternalDisable, loadPrefs, type SidebarSettingsClient } from '../src/client/prefs.ts'
|
||||
import { allLeaves, createSidebarStore, defaultWidthFor, makeDefaultState, setWidth } from '../src/client/state.ts'
|
||||
import { SIDEBAR_PREFS_DEFAULTS } from '../src/prefs-shared.ts'
|
||||
|
||||
@@ -416,3 +416,28 @@ describe('external disable (aionui-panel provider choice)', () => {
|
||||
expect(await loadExternalDisable(rejecting())).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('boot decision (one fetch for prefs + external disable)', () => {
|
||||
it('answers both decisions from a single settingsGet call', async () => {
|
||||
let calls = 0
|
||||
const counting = (): SidebarSettingsClient => ({
|
||||
settingsGet: async () => { calls += 1; return { value: { openByDefault: true, defaultWidthPercent: 40 }, revision: 1, externalDisable: true } },
|
||||
settingsUpdate: async () => ({ value: {}, revision: 2 }),
|
||||
})
|
||||
const decision = await loadBootDecision(counting())
|
||||
expect(calls, 'the boot path must fetch the settings document exactly once').toBe(1)
|
||||
expect(decision.suspended).toBe(true)
|
||||
expect(decision.prefs.openByDefault).toBe(true)
|
||||
})
|
||||
|
||||
it('falls back to the defaults + not suspended on any failure', async () => {
|
||||
const decision = await loadBootDecision(rejecting())
|
||||
expect(decision).toEqual({ prefs: SIDEBAR_PREFS_DEFAULTS, suspended: false })
|
||||
})
|
||||
|
||||
it('reads suspended false when the flag is absent', async () => {
|
||||
const decision = await loadBootDecision(wire({ defaultWidthPercent: 50 }))
|
||||
expect(decision.suspended).toBe(false)
|
||||
expect(decision.prefs.defaultWidthPercent).toBe(50)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user