Conversation
- SaveActiveSessionsToDisk: 2s debounce timer coalesces rapid saves - SaveOrganization: 2s debounce timer (called from 12+ places) - SaveUiState: 1s debounce with pending state object - ReconcileOrganization: skip if session set unchanged (hash check) - GetOrganizedSessions: cached result invalidated by hash key - Markdown cache: use string key (no hash collisions), LRU eviction at 1000 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
RefreshState was prematurely clearing _sessionSwitching before SafeRefreshAsync could read it, causing the expensive JS draft capture round-trip to execute during every session switch. Before: 729-4027ms per switch After: 16-28ms per switch (50-150x improvement) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
LoadPersistedSessions() was called from RefreshSessions() on every OnStateChanged event, scanning all session directories for resumable sessions. This scans workspace.yaml + events.jsonl for each dir. Now only loads persisted sessions on init and when the section is explicitly toggled open. Reduces steady-state I/O dramatically. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Two new domain knowledge skills for future agents: - performance-optimization: 5 critical invariants (session switching, debounce flush, LoadPersistedSessions danger, cache invalidation, ReconcileOrganization skip guard), caching architecture, known optimization opportunities - processing-state-safety: 9-item cleanup checklist, 8 IsProcessing paths table, 8 invariants, top 3 regression patterns, reference to full regression history across 7 PRs Also adds brief performance pointers to copilot-instructions.md with links to the skills for detailed reference. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tests cover: - GetOrganizedSessions caching (same instance when unchanged) - Cache invalidation on group add, sort mode change, group delete - Organization operations (create, delete, move, pin, collapse) - SaveUiState rapid-fire without corruption - DisposeAsync safety (flush + idempotent) - GetOrganizedSessions returns IReadOnlyList 836 total tests passing (822 existing + 14 new) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- LoadUiState returns pending debounced state instead of stale disk data - DisposeAsync flushes pending UI state (was only disposing timer) - SaveOrganization invalidates organized sessions cache immediately - ReconcileOrganization hash is now order-independent (XOR) - Added 6 edge case tests (842 total passing) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Snapshot JSON/entries on caller's thread before passing to Timer callback, preventing concurrent mutation of Organization lists and session History - Add IsRestoring guard to FlushSaveActiveSessionsToDisk (prevents partial writes during app startup if dispose is called mid-restore) - Replace XOR hash with additive hash in ReconcileOrganization (fewer collisions) - Remove Task.Run wrappers from SaveUiState calls (no longer needed since SaveUiState is now in-memory + debounce timer, eliminates read-modify-write race) Findings from: Opus 4.6, Codex 5.3, Sonnet 4.6 code reviews Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
25406e9 to
969ccaf
Compare
- SaveOrganization snapshot-on-caller doesn't throw under rapid mutations - SaveOrganization state is captured before timer fires - FlushSaveActiveSessionsToDisk respects IsRestoring during dispose - ReconcileOrganization hash handles group create/delete churn - SaveUiState is non-blocking (<500ms for 100 calls, returns latest state) - Rapid group mutations don't corrupt organization state - 883 total tests passing (26 in PerformanceOptimizationTests) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Mac Catalyst was very slow when:
[SwitchPerf]logs)Fast on Android/Windows and for new users — the issue scaled with accumulated data (753 session dirs, 463MB events.jsonl).
Root Causes Found & Fixed
1. JS draft capture running during every session switch (biggest impact)
_sessionSwitchingflag was cleared prematurely inRefreshState()beforeSafeRefreshAsync()could read it. This caused an expensive round-trip JS interop call (querying all card inputs, capturing draft text, focus, cursor position) to execute on every single session switch.Before: 729–4027ms per switch | After: 16–28ms (50-150x faster)
2. Synchronous disk I/O on every state change
SaveActiveSessionsToDisk(): sync read + merge + write ofactive-sessions.jsoncalled 7+ times per operationSaveOrganization(): sync write called from 12+ locationsSaveUiState(): sync read-modify-write on UI threadFix: Timer-based debounce (2s for sessions/org, 1s for UI state) coalesces rapid saves. Flush on dispose.
3.
GetOrganizedSessions()recalculated on every renderCreated dictionaries, iterated all sessions per group, sorted — on every
StateHasChanged().Fix: Cache with hash-key invalidation (session count + group count + sort mode + per-session state).
4.
LoadPersistedSessions()scanning 753 directories on every state changeRefreshSessions()calledGetPersistedSessions()which readsworkspace.yaml+events.jsonlfrom every session directory.Fix: Only load persisted sessions on init and when the section is explicitly toggled open.
5. Markdown cache hash collisions + no eviction
Used
GetHashCode()as key (collision risk). Capped at 500 with no eviction.Fix: String content as key, LRU eviction at 1000 entries.
6.
ReconcileOrganization()running unnecessarilyFull reconciliation (disk reads, directory checks) ran after every session operation even when nothing changed.
Fix: Hash-based skip when session set unchanged.
Test Results