perf(notebook): cut iframe message churn via cell diffing and stable callbacks#922
Closed
perf(notebook): cut iframe message churn via cell diffing and stable callbacks#922
Conversation
Compare each incoming cell against the existing one before inserting into the map. If structurally equal, preserve the old reference — useCell(id) subscribers won't re-render. Replace the blanket emitAllCellChanges() with targeted per-cell notifications for cells that actually changed. emitSourceChange() only fires when at least one cell's source actually changed. cellsEqual() uses: - String equality for cell_type, source - Strict equality for execution_count - Referential equality per output element (output cache cooperation) - Shallow record comparison for metadata and resolvedAssets
…dFrame C1: Wrap CodeCell, MarkdownCell, RawCell in React.memo(). Without this, every cell re-renders when any cell in the notebook changes. C2: Extract inline onError in OutputArea to module-level constant. Eliminates a new closure every render that defeated IsolatedFrame memo and caused message handler churn. C3: Store all IsolatedFrame callback props in refs, sync during render, read from refs in the message handler. Dependency array shrinks from 11 entries to 4 (only value props). Handler is only re-registered when initialContent/minHeight/maxHeight/autoHeight change — not on every callback identity change. C5: Extract inline onError in MarkdownCell to module-level constant. Bonus: Stable onLinkClick in CodeCell via useCallback.
Member
|
You goofball. I asked for a review, not a new PR. |
Member
|
Rebase against main @codex |
|
To use Codex here, create an environment for this repo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cell execution still triggered iframe message storms because every cell re-rendered on minor changes and IsolatedFrame re-registered handlers on each render.
replaceNotebookCellsnow retains object references for unchanged cells and emits change events only for modified ones, preventinguseCellsubscribers from re-rendering unnecessarily.CodeCell,MarkdownCell, andRawCellare wrapped inReact.memo, blocking parent re-renders from propagating when props are stable.useCallback, eliminating per-render closures.Example: IsolatedFrame now keeps handler registrations stable while still honoring latest callbacks: