Repository navigation
perf: reduce notebook log append cost - #12248
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
React Doctor found 1 new issue in 1 file · 1 warning · score 91 / 100 (Great) · 0 fixed · vs 1 warning
Reviewed by React Doctor for commit |
Coverage Report for ./frontend
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
🟡 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
|
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. Clear removed all rows. The next stderr entry appeared at row 1. |



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