Skip to content

perf(notebook): draw only the end of long cell output, at bounded cost per frame - #28967

Closed
brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/notebook-bounded-output-drawing
Closed

brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/notebook-bounded-output-drawing

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​222 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​211
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​663 $\color{#cf222e}{\Huge{\mathbf{−}}}$​88 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​575

ELI5

A notebook cell that printed a large amount of text could freeze the Orca window because each update made the window process and draw accumulated output. The cell now shows a bounded end of each long text output while keeping the complete output for saving. Changing a progress line reuses the completed text already drawn.

What Changed

Text output shows its last 5,000 lines and at most 1,048,576 UTF-16 units. “Earlier output is hidden.” appears above truncated text. A cell draws at most 500 output records; the latest error and final record remain visible, with the selected records in their original order. The existing hidden-output count stays below the outputs.

Completed text is retained as small immutable pieces, with the changing current line interpreted separately. Pieces carry color state through the existing parser and become reusable once their control sequences are settled. Carriage-return updates process incoming text and retained line metadata instead of scanning an arbitrarily long earlier line. Saved text arrays select a bounded suffix before joining and normalizing it. The full notebook data remains separate from these drawing caches.

Why

Keeping output was not the source of the repeated drawing work. Separating saved data from visible text preserves the user's results while avoiding repeated processing of completed text. Dropping old output would lose data; rescanning the full output before taking its end would retain the original growing cost.

The common pattern retains completed presentation and updates the changing suffix. Intended differences are the exact combined line/character cap, existing carriage-return and color-code behavior, and retaining final diagnostics inside the output-record limit. A color sequence cut by the outer display boundary still starts with fresh color state and can leave stray characters, as on the original bounded implementation.

Temporary gaps: opening hidden output in a read-only editor is tracked in STA-10710; reopening notebooks larger than the existing 50 MB file-opening limit is tracked in STA-10711. This change also does not bound conversion of every display format or eliminate the initial visit to all output records.

Linked Issue

STA-8495 (duplicate STA-8641). Replaces #28087.

Visual Proof

Remote before/after Electron screenshots are pending. This PR remains in validation.

Testing

Current reviewed head: 9d980079727e8a6e415b849b26c1080104f0fe5a.

On a separate macOS machine, the ten named notebook and shared ANSI test files passed: 150 passed, four existing skips. These cover complete saved output and reducer parity, caps, latest-error/final-record selection, completed DOM retention, and bounded parser/range-discovery inputs. The branch Electron production build also passed. The normal pre-commit hook passed before pushing.

The full PR workflow is pending on the current head. Actual main/branch Electron interaction, screenshots and the same-machine performance rerun remain pending; passing unit tests and the build do not establish those results.

Earlier measurements on this machine found a 55–114 ms first-output layout task. That is a known measurement limitation awaiting the repaired-head rerun, not a timing claim about the current commit. Full JSON parsing/saving, display-format conversion, visiting all output records and aggregate notebook memory remain outside the drawing guarantee.

  • Remote main/branch rendered QA and performance rerun complete
  • Automated regression tests passed on the current head

Review

Three semantic review rounds and the final independent three-model design panel are complete; all three accepted the design. Final runtime validation, review-thread disposition and the loop status comment remain pending.

Agent skill upstream boundary

  • Not applicable: no upstream skill-installer material is copied or translated.

Notes

Saved output and Source view retain complete notebook data. Folder workspaces use the same drawing path. This adds no persisted format or remote protocol field. Notebook execution keeps its existing local-file restriction; remote notebooks receive the saved-output drawing behavior.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 15, 2026 03:37
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Notebook output parsing and rendering now use bounded drawn-text tails. Live stream handling tracks chunks and carriage-return rewrites, while parsed stream and error outputs carry a DrawnText value. ANSI styles can persist across drawn blocks. Each cell renders up to the configured output limit and shows notices for hidden text or outputs. Tests cover truncation, live stream updates, parsing, ANSI handling, and rendered notices. Translations cover English, Spanish, French, Japanese, Korean, and Chinese.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 9d980

Large notebook outputs can still cause expensive first renders. Bound conversion and parsing before merging unless that remaining performance risk is explicitly accepted.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 36.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 38 functions across 14 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main change: limiting notebook cell output drawing to the end of long output with bounded per-frame cost.
Description check Passed The description is substantially complete and covers the user impact, implementation, rationale, linked issue, testing, limitations, and review status. Visual proof, full workflow validation, and some…
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 30a5a096-c7c4-4e50-aa32-5b14fb8680c7
📥 Commits

Reviewing files that changed from the base of the PR and between d717798 and 818458b.

📒 Files selected for processing: 17
  • src/renderer/src/components/editor/IpynbCellOutputs.tsx
  • src/renderer/src/components/editor/IpynbRendering.test.tsx
  • src/renderer/src/components/editor/ipynb-kernel-outputs.test.ts
  • src/renderer/src/components/editor/ipynb-kernel-outputs.ts
  • src/renderer/src/components/editor/ipynb-output-tail.test.ts
  • src/renderer/src/components/editor/ipynb-output-tail.ts
  • src/renderer/src/components/editor/ipynb-parse.test.ts
  • src/renderer/src/components/editor/ipynb-parse.ts
  • src/renderer/src/components/editor/ipynb-stream-text.ts
  • src/renderer/src/components/editor/useIpynbCellExecution.test.tsx
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

return <IpynbMarkdownCell source={valueToText(item.value)} />
}
return <TextOutput text={valueToText(item.value)} />
return <TextOutput drawn={drawnText(valueToText(item.value))} />

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.

🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift

Bound plain-text display data before converting it.

If a text/plain display item holds a large line array, valueToText(item.value) joins the entire array before drawnText keeps its tail. Opening that output still allocates and processes the full text. Apply the bounded multiline conversion before rendering the plain-text item.

return (
<div className="flex min-w-0 flex-col gap-1 pt-2">
{cell.outputs.map((output, index) => (
{cell.outputs.slice(0, DRAWN_OUTPUTS_PER_CELL).map((output, index) => (

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.

🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift

Apply the output limit before parsing all outputs.

This slice bounds React output elements, but parseCell in src/renderer/src/components/editor/ipynb-parse.ts first maps parseIpynbOutput over every raw output. A cell with many outputs therefore still parses and allocates an unbounded number of records on its first draw. Carry the raw output count for the notice, and parse only the outputs that can be shown.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments: 1
src/renderer/src/components/editor/IpynbRendering.test.tsx: 1

138-139: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Require both spies to record calls.

The bound assertion passes for an empty call list because Math.max(...[]) returns -Infinity. Assert that both ANSI operations ran before checking their maximum input sizes.

Suggested fix
+      expect(parseSizes).not.toHaveLength(0)
+      expect(rangeSizes).not.toHaveLength(0)
       for (const sizes of [parseSizes, rangeSizes]) {
         expect(Math.max(...sizes)).toBeLessThanOrEqual(chain ? 17 : 8192)

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f86daf46-bd0b-41bc-8ee3-f96ac36bd313
📥 Commits

Reviewing files that changed from the base of the PR and between e6b3b74 and 9d98007.

📒 Files selected for processing: 1
  • src/renderer/src/components/editor/IpynbRendering.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Large notebook output could freeze the window because each update redrew completed text. The original output limit also hid errors and kernel-exit details once a cell produced more than 500 output records.

The bounded view now reuses completed text while updating the changing progress line, preserves the previous color and carriage-return behavior, and keeps the latest error and final output visible within the 500-record limit. Complete output remains available to saving and Source view. The review also removed the historical scan of an arbitrarily long unfinished line and bounded saved text-array preparation before joining it.

Verification on current head 9d980079727e8a6e415b849b26c1080104f0fe5a: the branch production Electron build and 150 tests in ten named notebook/ANSI files passed on another machine, with four existing skips. The normal pre-commit hook passed. CI lint/typecheck and Windows packaging passed. The full PR workflow is still pending in run 38833414487; main/branch Electron screenshots and same-machine before/after measurements have not run. The final three-model panel unanimously accepted the design after three review rounds. Source review found no further confirmed issue after the two interpretation-boundary corrections; this alone does not establish runtime readiness.

Remaining limits: full display-format conversion, visiting every saved output record, complete notebook serialization, and aggregate memory are outside the drawing guarantee. The earlier 55–114 ms first-output layout task remains an open measurement limitation; the repaired-head rerun has not established a new value. Opening hidden output in a read-only editor is tracked in STA-10710; reopening saved notebooks over 50 MB is tracked in STA-10711.

Remote validation is blocked, so this PR is not ready to merge. The available test machines repeatedly fell below the required memory headroom. On the original measurement machine, every approved UI driver also failed its startup check through authentication, unavailable-model or quota errors. No test Orca window was launched; there are no screenshots to review yet. These are missing results, not passing checks. The two remaining review threads concern the disclosed full display-data conversion and visit to every saved output record; neither is being claimed fixed.

For Brennan’s review

Still needed: whole-window main/branch screenshots of normal execution and saved tail diagnostics, the branch progress-identity check, and the same-machine performance rerun. The following source decisions have completed review:

@nwparker

Copy link
Copy Markdown
Contributor

Closing in favour of #27721: keeping full output brings back the write-back freezes and main/restart-backup growth measured in #28087. Drawing only the end of already-saved huge notebooks would be welcome as a smaller follow-up.

@nwparker nwparker closed this Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants