Repository navigation
perf(notebook): draw the end of long text output and keep the rest - #28087
Closed
brennanb2025 wants to merge 1 commit into
Closed
brennanb2025 wants to merge 1 commit into
brennanb2025 wants to merge 1 commit into
Conversation
A cell that prints without stopping made the window stop responding: every chunk redrew the whole growing text and re-scanned it. Text outputs now draw their last 5,000 lines (at most 1 MiB) under a truncation note, while the run and the saved notebook keep every byte. Live streams keep their drawn end from each chunk, and saved outputs build it from their line array, so nothing reads the whole text to draw it. STA-8495, STA-8641
8 of 9 tasks
brennanb2025
marked this pull request as ready for review
October 12, 2026 21:58
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 6 minutes. View limit details
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. Comment |
brennanb2025
marked this pull request as draft
October 13, 2026 05:11
2 of 3 tasks
Contributor
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.
ELI5
When a notebook cell printed a lot of text (for example a loop that keeps printing), Orca tried to draw all of it on screen and re-read all of it every time a new piece arrived. With a couple hundred MB of output the window used over 10 GB of memory and stopped responding. Now Orca keeps every byte of the output, but only draws the end of it, with a short note saying the output is truncated.
What Changed
Before: every chunk a running cell printed made Orca:
On a cell printing 200 MiB (1 MiB every 50 ms, real Python kernel), the window grew to about 12 GB and stopped answering before 50 MiB had arrived. It never finished.
After: a text output (printed text, error tracebacks, plain-text results) draws at most its last 5,000 lines, and never more than 1 MiB of text even when there are no line breaks. A note at the top of the box reads "Output is truncated. Showing the end; the full output is kept in the notebook." Nothing is dropped:
.ipynb.How the drawn end is kept cheap:
This is the common pattern for notebook output: keep everything, bound only what is drawn, show the last lines with a truncation note.
Intended differences from that pattern:
Known limit, not fixed here: Orca holds an open notebook as one JSON text. When a run finishes, and on every later write-back (running another cell, an edit being committed), the whole notebook is re-parsed and re-serialised. With 200 MiB of output kept, each of those freezes the window for about 0.6–0.8 s, and the renderer holds roughly 650 MB. Removing that means holding notebooks as a structured model and serialising only on save, which is a larger refactor. A companion PR (#28088) stops the same notebook text from also being copied into the restart-recovery session on every change, which is what grew main-process memory.
Why
The earlier fix (#27721) dropped output past a retention budget and kept only the beginning. This PR follows the common pattern instead: nothing the program printed is thrown away, and the saved notebook matches what ran. Measurement showed the freeze came from drawing and re-scanning the whole text, not from keeping it, so bounding what is drawn removes the freeze without losing output.
The trade-off is plain in the numbers below. #27721 uses less memory after the stream, because it keeps only about 2 MiB. This PR keeps all 200 MiB and pays for it in memory and in the write-back freezes described above.
Linked Issue
STA-8495 (duplicate STA-8641). Replaces #27721.
Visual Proof
PR head in a hidden production build, after a 200 MiB cell finished. The note sits above the drawn end of the output, and the window stays usable:
Main could not be captured: the window stopped answering before any screenshot.
Testing
Setup: same Mac, hidden production builds, a real Python 3.14 / ipykernel cell printing 200 MiB (1 MiB per write, 50 ms apart). Three fresh app launches each, interleaved main → this PR → #27721.
Harness: counts bytes reaching the window; forces garbage collection; samples the JavaScript heap, renderer and main-process memory; records long tasks (main-thread work over 50 ms). After the stream it runs a one-line second cell five times, to measure later write-backs.
During the stream (series 1: main / this PR / #27721; median (range), n = 3 each)
After the stream (series 2: this PR / #27721, quieter host; median (range), n = 3 each)
The host had other work running during part of the series, so the freeze times are indicative; the memory numbers were stable across runs.
Automated tests:
All 110 notebook tests and the web typecheck pass.
AI Disclosure
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)