Skip to content

Reuse the source model snapshot during mount - #34921

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/editor-mount-snapshot
Oct 29, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/editor-mount-snapshot

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 0 0 0 0
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

Problem

On every source-editor mount (opening or switching a tab, remounting a pane), the retained-model reconciliation in use-monaco-editor-mount.ts calls model.getValue() for the stale-cache guard, then syncContentOnMount calls model.getValue() again on the same model. Each call rebuilds the full text from Monaco's piece tree, so large files pay for two full-text copies per mount.

Fix

syncContentOnMount takes an optional currentContentSnapshot. The mount hook passes the text it already read. Nothing between the read and the sync mutates the model (only store reads and the programmatic-sync marker). Other callers (AutomationEditorPromptEditor) omit it and fall back to model.getValue(). EOL normalization, the no-undo-stop mount edit, stale-cache refusal and dirty-view protection are unchanged.

Test

  • pnpm test src/renderer/src/components/editor/monaco-content-sync.test.ts src/renderer/src/components/editor/use-monaco-editor-mount.stale-cache.test.tsx: existing tests pass. No new tests were added, because this change keeps the same behavior.
  • pnpm check:changed --maxWorkers=2: passes.

@OrcaWin
OrcaWin force-pushed the OrcaWin/editor-mount-snapshot branch from 1b22ad9 to 82a89e2 Compare October 28, 2026 23:12
@OrcaWin
OrcaWin marked this pull request as ready for review October 29, 2026 00:08
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 258e4a0a-6883-4376-b4b2-a2c177129236
Commits

Reviewing files that changed from the base of the PR and between b2feed0 and 5fa2586.

Files selected for processing: 2
  • src/renderer/src/components/editor/monaco-content-sync.ts
  • src/renderer/src/components/editor/use-monaco-editor-mount.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; the remaining test-coverage suggestion is non-blocking.

Findings

  1. P2 Saved read lacks test coverage ▶

Summary

Reuses the text already read during source-editor mount instead of reading the full model again.

  • Source editor mounts reuse their first model text read.

Reviews (2) · Last reviewed commit: "perf(editor): reuse the content snapshot..." · Reviewed by Greptile

const currentContent = model.getValue()
const normalizedContent = normalizeToModelEol(content, model, currentContent)
if (currentContent === normalizedContent) {
const modelContent = currentContentSnapshot ?? model.getValue()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Saved read lacks test coverage

Existing syncContentOnMount tests omit the new fourth argument, so bringing back the extra full-text read would still pass them. Add focused tests that supply currentContentSnapshot, including '', and assert that getValue() is not called. Also check that differing content still gets applied without undo stops. This is non-blocking, but would protect the performance improvement this PR makes.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

The mount reconciliation already reads the full model text for its
stale-cache guard. Pass that snapshot into syncContentOnMount so a mount
reads the model once instead of twice.
@OrcaWin
OrcaWin force-pushed the OrcaWin/editor-mount-snapshot branch from 82a89e2 to 5fa2586 Compare October 29, 2026 00:27
@OrcaWin
OrcaWin merged commit 7a614b0 into main Oct 29, 2026
35 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