Skip to content

perf: reduce notebook log append cost - #12248

Merged
kirangadhave merged 1 commit into
mainfrom
kg/mo-8797-log-append-cost
Dec 3, 2026
Merged

kirangadhave merged 1 commit into
mainfrom
kg/mo-8797-log-append-cost

Conversation

@kirangadhave

@kirangadhave kirangadhave commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

📝 Summary

Each time a cell prints to stdout or stderr, the notebook copies every earlier log entry into a new array. For 8,000 individual writes, it copies 31,996,000 old references. The editor pays this cost even with the Logs panel closed.

Store notebook logs in immutable chunks of 128 entries. A live append copies the chunk references and the partial tail. A command-output batch fills the tail and adds new chunks in order. The Logs panel renders chunks directly and reuses rows from full chunks.

The table shows median process CPU time in milliseconds for 8,000 entries from one cell. Each run checks the complete log in order. The periodic-read runs also scan the log after every 16 actions.

Entries per action Reads Before After
1 Final 23.490 0.883
32 Final 0.700 0.032
1 Periodic and final 23.468 2.678
32 Periodic and final 0.750 0.097

Nine paired samples ran on an Apple M4 Pro with Node 26.13.0. The fixture isolates the storage operation with prebuilt entries. Browser paint, console formatting, and transport time fall outside the measurement. The chunk-reference array still grows with the log.

The targeted tests cover order, immutable snapshots, replay, runtime reset, clear, and row numbers across chunk boundaries. After 128 visible entries, the next append formats one new row.

Addresses the log accumulation part of MO-8797.

@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 91 / 100 (Great) · 0 fixed · vs main

1 warning

src/components/editor/chrome/panels/logs-panel.tsx

  • ⚠️ L84 Array index used as a key no-array-index-as-key

Reviewed by React Doctor for commit e3fedd2. See inline comments for fixes.

@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.06% 28580 / 41382
🔵 Statements 69.01% 29131 / 42211
🔵 Functions 64.31% 6855 / 10659
🔵 Branches 64.48% 16746 / 25967
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/components/editor/chrome/panels/logs-panel.tsx 72.22% 25% 83.33% 72.22% 27-52
frontend/src/core/cells/cell-log-chunks.ts 100% 100% 100% 100%
frontend/src/core/cells/cells.ts 84.83% 85.33% 75.94% 88.23% 275-282, 311-332, 434, 443-447, 450, 516, 523, 538, 543, 548, 560, 567, 572, 575, 633-635, 676, 692-697, 715-719
frontend/src/stories/log-viewer.stories.tsx 0% 100% 0% 0% 9-84
Generated in workflow #26496 for commit e3fedd2 by the Vitest Coverage Report Action

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.

🟡 Changes recommended

The Logs panel rendering change lacks browser evidence for key edge cases, and the reported benchmark excludes rendering.

1 open issue
What changed in this PR

Reduces notebook log accumulation costs by storing entries in immutable chunks and reusing completed chunks when rendering the Logs panel.

Changes:

  • Introduces 128-entry chunks for individual and batched log appends.
  • Memoizes chunk rendering to avoid reformatting completed chunks.
  • Updates tests and Storybook examples for chunked storage.
File Description
frontend/​src/​stories/​log-viewer.stories.tsx Adapts the story to chunked logs.
frontend/​src/​core/​session/​__tests__/​useNotebookSession.hook.test.tsx Updates assertions and checks replay logging behavior.
frontend/​src/​core/​islands/​__tests__/​bridge.test.ts Adapts bridge assertions to chunks.
frontend/​src/​core/​codemirror/​lsp/​__tests__/​transports.test.ts Adapts transport log assertions.
frontend/​src/​core/​codemirror/​lsp/​__tests__/​log-messages.test.ts Adapts language-server log assertions.
frontend/​src/​core/​cells/​cells.ts Integrates chunked storage into notebook state.
frontend/​src/​core/​cells/​cell-log-chunks.ts Adds immutable chunk append logic.
frontend/​src/​core/​cells/​__tests__/​cells.test.ts Covers ordering, snapshots, reset, and clearing.
frontend/​src/​components/​editor/​chrome/​panels/​logs-panel.tsx Renders memoized chunks with continuous numbering.
frontend/​src/​components/​editor/​chrome/​panels/​__tests__/​logs-panel.test.tsx Checks boundary numbering and formatting reuse.

Review effort: Balanced

@kirangadhave
kirangadhave marked this pull request as ready for review December 2, 2026 22:17
@kirangadhave

Copy link
Copy Markdown
Member Author

Verified the Logs panel on the production build of e3fedd2 in Chromium 156. I closed the panel, wrote 128 stdout entries, and reopened it. All 128 rows appeared in order. The next write was a long stderr diagnostic. It appeared in full at row 129 and wrapped without horizontal overflow.

Row 129 shows the complete stderr diagnostic after 128 stdout entries

Clear removed all rows. The next stderr entry appeared at row 1.

The first stderr entry after clearing the log

@kirangadhave kirangadhave added the internal A refactor or improvement that is not user facing label Dec 3, 2026
@kirangadhave
kirangadhave enabled auto-merge (squash) December 3, 2026 00:59
@kirangadhave kirangadhave changed the title Reduce notebook log append cost perf: reduce notebook log append cost Dec 3, 2026
@kirangadhave
kirangadhave merged commit f2fd1f2 into main Dec 3, 2026
37 of 39 checks passed
@kirangadhave
kirangadhave deleted the kg/mo-8797-log-append-cost branch December 3, 2026 04:41
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