Skip to content

perf: recycle codemirror EditorView across source-mode file opens#238

Merged
code-alexander merged 2 commits into
mainfrom
dev
Apr 12, 2026
Merged

perf: recycle codemirror EditorView across source-mode file opens#238
code-alexander merged 2 commits into
mainfrom
dev

Conversation

@code-alexander

Copy link
Copy Markdown
Collaborator

No description provided.

code-alexander and others added 2 commits April 12, 2026 14:35
instead of destroying and recreating the EditorView on every file
navigation, keep a module-level singleton and swap its state via
view.setState(). also cache resolved language extensions so subsequent
opens skip the async dynamic import.

- add language cache + getLanguageSupportSync() in codemirror-editor.tsx
- extract buildSourceEditorState() factory (pure, no DOM dependency)
- add source-view-pool.ts (init/recycle/destroy singleton)
- refactor source-editor.tsx lifecycle: refs for all closures, per-file
  cleanup without view destruction, compartment refresh on setState()
- remove key prop from source-mode <Editor> so React reuses the tree
- add e2e/latency-benchmark.spec.ts measuring click-to-content latency

benchmark results (10 source-mode files, single rep):
  cold open avg: 125ms -> 84ms (-33%)
  warm open avg: 80ms -> 76ms (-5%)
  overall avg:   102ms -> 80ms (-22%)
  worst case:    314ms -> 104ms (-67%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
replace viewRef.current! with a typed local variable after the
init/recycle branch. extract flushPendingWork() helper to eliminate
duplicated flush/cancel/autosave logic between per-file and unmount
cleanup effects. add diagnostic warning on the reparent path in the
source view pool.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Apr 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spacecake Ready Ready Preview, Comment Apr 12, 2026 5:00am

@code-alexander
code-alexander merged commit 7308ce6 into main Apr 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant