Skip to content

perf: skip language panel renders for routine editor updates - #12246

Merged
kirangadhave merged 1 commit into
mainfrom
kg/editor-panel-renders
Dec 3, 2026
Merged

kirangadhave merged 1 commit into
mainfrom
kg/editor-panel-renders

Conversation

@kirangadhave

@kirangadhave kirangadhave commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

📝 Summary

Skip React re-renders of the Markdown and SQL language panels on CodeMirror updates that do not change what the panel displays. createPanel now takes an optional shouldRender predicate. 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 main at 06fe945858.

Panel Root render calls, main → this PR Median time per batch, main → this PR
Markdown 100 → 0 26.9 ms → 7.1 ms
SQL 200 → 0 93.9 ms → 8.5 ms

A 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.

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.
@kirangadhave
kirangadhave marked this pull request as ready for review December 2, 2026 21:02
Copilot AI balanced review requested due to automatic review settings December 2, 2026 21:02
@kirangadhave kirangadhave added the internal A refactor or improvement that is not user facing label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

React Doctor found 1 new issue in 1 file · 1 warning · score 98 / 100 (Great) · 0 fixed · vs main

1 warning

src/core/codemirror/language/panel/panel.tsx

  • ⚠️ L28 Non-component export in component file only-export-components

Reviewed by React Doctor for commit 6b6113f. See inline comments for fixes.

import { getQuotePrefix, MarkdownQuotePrefixTooltip } from "./markdown";
import { SQLEngineSelect, SQLModeSelect } from "./sql";

export function languagePanelInputsChanged(update: ViewUpdate): boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Docs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 69.08% 28578 / 41367
🔵 Statements 69.03% 29128 / 42195
🔵 Functions 64.35% 6859 / 10658
🔵 Branches 64.49% 16744 / 25962
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/core/codemirror/language/extension.ts 71.25% 70% 78.94% 70.88% 112-116, 126-144, 331-353
frontend/src/core/codemirror/language/panel/panel.tsx 73.8% 72.22% 50% 73.17% 69-74, 78-79, 91-125, 153, 174
frontend/src/core/codemirror/react-dom/createPanel.tsx 90% 66.66% 83.33% 90% 11
Generated in workflow #26494 for commit 6b6113f by the Vitest Coverage Report Action

@kirangadhave
kirangadhave merged commit cc2705e into main Dec 3, 2026
43 of 45 checks passed
@kirangadhave
kirangadhave deleted the kg/editor-panel-renders branch December 3, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants