Repository navigation
Reuse the source model snapshot during mount - #34921
Conversation
1b22ad9 to
82a89e2
Compare
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
[Low impact] The PR appears safe to merge; the remaining test-coverage suggestion is non-blocking. Findings
SummaryReuses the text already read during source-editor mount instead of reading the full model again.
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() |
There was a problem hiding this comment.
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.
82a89e2 to
5fa2586
Compare
Problem
On every source-editor mount (opening or switching a tab, remounting a pane), the retained-model reconciliation in
use-monaco-editor-mount.tscallsmodel.getValue()for the stale-cache guard, thensyncContentOnMountcallsmodel.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
syncContentOnMounttakes an optionalcurrentContentSnapshot. 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 tomodel.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.