perf(ui): improve mobile session switching

Treat the mobile web surface as a constrained runtime so sync loads smaller message pages, keeps fewer warm session caches, and evicts heavy inactive sessions instead of retaining them across switches.

Limit mobile message-record and turn-model caches to reduce memory pressure on phones while preserving bounded initial page expansion for large final turns.

Split the mobile session status bar so the collapsed state avoids subscribing to the full session/status list; the expensive grouping work now only mounts for the expanded list.

Verified with bun run type-check and bun run lint.
This commit is contained in:
Bohdan Triapitsyn
2026-05-25 01:39:47 +03:00
parent f14fa1b307
commit bb3a51db39
5 changed files with 313 additions and 90 deletions
@@ -14,6 +14,7 @@ import {
import type { TurnHistorySignals } from '../lib/turns/historySignals';
import { getMemoryLimits, type SessionHistoryMeta } from '@/stores/types/sessionTypes';
import { isVSCodeRuntime } from '@/lib/desktop';
import { isMobileSurfaceRuntime } from '@/lib/runtimeSurface';
type ViewportAnchor = { messageId: string; offsetTop: number };
@@ -63,12 +64,19 @@ export interface UseChatTimelineControllerResult {
const TURN_MODEL_CACHE_MAX = 30
const VSCODE_TURN_MODEL_CACHE_MAX = 4
const VSCODE_TURN_MODEL_CACHE_MAX_MESSAGES = 30
const MOBILE_TURN_MODEL_CACHE_MAX = 4
const MOBILE_TURN_MODEL_CACHE_MAX_MESSAGES = 30
const turnModelCache = new Map<string, { messages: ChatMessageEntry[]; model: TurnWindowModel }>()
const getTurnModelCacheMax = () => isVSCodeRuntime() ? VSCODE_TURN_MODEL_CACHE_MAX : TURN_MODEL_CACHE_MAX
const getTurnModelCacheMax = () => {
if (isVSCodeRuntime()) return VSCODE_TURN_MODEL_CACHE_MAX
if (isMobileSurfaceRuntime()) return MOBILE_TURN_MODEL_CACHE_MAX
return TURN_MODEL_CACHE_MAX
}
const shouldCacheTurnModelMessages = (messages: ChatMessageEntry[]): boolean => {
if (!isVSCodeRuntime()) return true
return messages.length <= VSCODE_TURN_MODEL_CACHE_MAX_MESSAGES
if (isVSCodeRuntime()) return messages.length <= VSCODE_TURN_MODEL_CACHE_MAX_MESSAGES
if (isMobileSurfaceRuntime()) return messages.length <= MOBILE_TURN_MODEL_CACHE_MAX_MESSAGES
return true
}
const rememberTurnModel = (key: string, value: { messages: ChatMessageEntry[]; model: TurnWindowModel }) => {