perf(chat): make session switching feel instant
Switching sessions ran as one synchronous commit: sidebar highlight, URL, a full timeline remount with markdown re-parse, and around nine requests, so nothing changed on screen for 150-250ms after the click. - ChatContainer swaps the timeline on a deferred copy of the selection, so the active row, URL, and tab commit first and the timeline renders behind them; selection policy keeps reading the live store value. - The message fetch starts before the selection is published. - Sidebar rows stop re-rendering on a project switch: directory-scoped sync hooks read the runtime context and a subscribable current-directory source instead of the directory-bearing context; the grouping builder reads git branches through a ref and section caches key the branches they use; descendant ids are keyed by content. Rows per switch went from 73 to 8. - Markdown skips the async re-render when the settled cached blocks are already painted, and mounts synchronously once its lazy module is loaded; the module is preloaded at boot. - A timeline reveal gate holds a freshly opened session at opacity 0 while any provisional markdown paint catches up (250ms cap), then fades the whole timeline in once, so text, tools, and recap appear together. - Switch fan-out trimmed: knowledge summary deduped, MCP status refreshed only when stale, non-repo directories cached by the git repo check, OpenChamber defaults cached briefly, agent memory reused for the same project, goal text cached, PWA manifest rebuilt after the switch settles. - Header tabs snap into the active state and keep the title at the same height in both states. - Prefetch on row press; composer focus moved off the commit. `bun run profile:switch` records ack/content latency, longest task, and requests per switch, cold and warm, and compares runs against a baseline. Measured warm switch: ack 228ms to about 40-60ms, content 228ms to about 100-120ms.
This commit is contained in:
@@ -22,6 +22,9 @@ export function useSessionGoal(sessionId: string, directory?: string): SessionGo
|
||||
};
|
||||
}
|
||||
|
||||
const OBJECTIVE_CONTENT_CACHE_MAX = 64;
|
||||
const objectiveContentByFetchKey = new Map<string, Promise<string | null>>();
|
||||
|
||||
// Effective objective text for display. Inline goals return the metadata
|
||||
// text directly; file-backed goals fetch the server-side file once per
|
||||
// goal edit (keyed by id + updatedAt). Display-only: a failed fetch yields
|
||||
@@ -37,7 +40,18 @@ export function useGoalObjectiveContent(sessionId: string, goal: SessionGoalPayl
|
||||
return undefined;
|
||||
}
|
||||
let alive = true;
|
||||
void fetchGoalObjectiveContent(sessionId).then((content) => {
|
||||
// The key already names the goal edit, so a remount (every session switch
|
||||
// remounts the strip) reuses the text instead of fetching the file again.
|
||||
let request = objectiveContentByFetchKey.get(fetchKey);
|
||||
if (!request) {
|
||||
request = fetchGoalObjectiveContent(sessionId);
|
||||
objectiveContentByFetchKey.set(fetchKey, request);
|
||||
if (objectiveContentByFetchKey.size > OBJECTIVE_CONTENT_CACHE_MAX) {
|
||||
const oldest = objectiveContentByFetchKey.keys().next().value;
|
||||
if (oldest !== undefined) objectiveContentByFetchKey.delete(oldest);
|
||||
}
|
||||
}
|
||||
void request.then((content) => {
|
||||
if (alive) setFetched(content);
|
||||
});
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user