Repository navigation
perf: skip language panel renders for routine editor updates - #12246
Conversation
Re-render the Markdown and SQL language panels only when their language metadata or cell id changes. Selection and edit transactions no longer schedule a React root render.
|
All contributors have signed the CLA ✍️ ✅ |
|
React Doctor found 1 new issue in 1 file · 1 warning · score 98 / 100 (Great) · 0 fixed · vs 1 warning
Reviewed by React Doctor for commit |
| import { getQuotePrefix, MarkdownQuotePrefixTooltip } from "./markdown"; | ||
| import { SQLEngineSelect, SQLModeSelect } from "./sql"; | ||
|
|
||
| export function languagePanelInputsChanged(update: ViewUpdate): boolean { |
There was a problem hiding this comment.
React Doctor · react-doctor/only-export-components (warning)
This file exports non-components, so Fast Refresh can't safely preserve component state.
Fix → Move non-component exports out of component files so Fast Refresh can preserve component state instead of full-reloading.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the language-panel render optimization.
No open issues 🎉
What changed in this PR
Reduces unnecessary React renders in marimo’s Markdown and SQL language panels during routine CodeMirror updates.
Changes:
- Adds an optional render predicate to
createPanel. - Limits language-panel renders to metadata or cell-ID changes.
- Adds tests for skipped renders, control updates, and language-switch lifecycle behavior.
| File | Description |
|---|---|
| frontend/src/core/codemirror/react-dom/createPanel.tsx | Adds conditional rendering while preserving initial mounting. |
| frontend/src/core/codemirror/language/panel/panel.tsx | Defines the input-change predicate and removes a redundant event wrapper. |
| frontend/src/core/codemirror/language/panel/panel.test.tsx | Tests render counts, controls, cell-ID changes, and panel lifecycle. |
| frontend/src/core/codemirror/language/extension.ts | Connects language panels to the render predicate. |
Review effort: Balanced
Coverage Report for ./frontend
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
📝 Summary
Skip React re-renders of the Markdown and SQL language panels on CodeMirror updates that do not change what the panel displays.
createPanelnow takes an optionalshouldRenderpredicate. The language panel re-renders only when the language metadata or the cell id changes. Initial render, metadata updates, the Markdown checkboxes, the SQL datasource controls and language switches are unchanged.Routine selection changes and edits now schedule zero React root renders in both panels. Each batch alternated 50 cursor moves with 50 one-character edits and let React settle after each dispatch. Each row is the median of ten measured batches after a warm-up, in Vitest with jsdom, against
mainat06fe945858.main→ this PRmain→ this PRA separate run with 25 panels (20 Markdown, 5 SQL) and 2,500 transactions batched in one React update went from 2,505 root render calls to 0, and median time went from about 116 ms to about 91 ms. Both runs measure React work in jsdom, not browser typing latency.
Closes MO-8795.