Skip to content

perf(notebook): draw the end of long text output and keep the rest - #28087

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/perf-notebook-render
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/perf-notebook-render

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​131 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​130
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​143 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​133

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:

  1. put the cell's whole output so far into the page as one block of text, so the browser had to lay out up to hundreds of MB of text;
  2. re-run a find-and-replace over the whole output (normalising line endings) on every redraw;
  3. scan the whole output for colour codes on every redraw.

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:

  • the running cell keeps all of its output;
  • the notebook takes all of it when the run finishes;
  • saving writes all of it to the .ipynb.

How the drawn end is kept cheap:

  • While a cell runs: each new chunk updates a small "drawn end" that is stored next to the output (the stream reducer already keeps per-output bookkeeping this way). Drawing and parsing never read the whole growing text.
  • For outputs already in the notebook: the drawn end is built from the saved list of lines, picking only the last ones, instead of joining every line into one string first.

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:

  • No "open in a text editor" link. Orca has no editor surface for a single output. The full output is in the notebook file, and the existing Source view shows it.
  • A 1 MiB cap on drawn characters. This covers a single endless line, which a lines-only limit would still draw whole.

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:

Truncation note above the drawn end of a 200 MiB output

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)

Before (main) After (this PR) #27721 (drops output)
Window while 200 MiB streams stopped answering before 50 MiB, 3/3 answered throughout answered throughout
Renderer memory, peak 11.8 GB (7.1–12.1) 510 MiB (471–524) 327 MiB (325–330)
All 200 MiB reached the window 0/3 3/3, 13.8 s (13.5–16.0) 3/3, 13.8 s (12.8–14.1)
Output kept everything (never finished) everything about the first 2 MiB
Text drawn all of it last 5,000 lines / 1 MiB the kept 2 MiB

After the stream (series 2: this PR / #27721, quieter host; median (range), n = 3 each)

After (this PR) #27721
Longest freeze when the run finishes 666 ms (652–781) 93 ms (93–93)
Longest freeze when a one-line cell runs afterwards 588 ms (576–749) none
JavaScript heap after the run 242 MiB (240–243) 42 MiB (41–42)
JavaScript heap after five more one-line runs 650 MiB (648–650) 50 MiB (50–51)
Main-process memory after those runs 3.45 GB (2.99–4.28); 367 MiB with #28088 386 MiB (384–387)

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:

  • the drawn end matches the whole text however chunks split, including carriage-return progress rewrites;
  • saved line arrays give the same drawn end as the joined text;
  • the note appears only when the output is cut;
  • a single endless line is capped.

All 110 notebook tests and the web typecheck pass.

  • I manually tested these changes locally
  • Automated tests added/updated

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: notebook cells only run for local files, so remote notebooks see only the saved-output drawing change.
  • Folder workspaces: behave the same.
  • Platforms: no platform-specific code. Measured on macOS only.
  • Saved notebooks: unchanged on disk. Opening a large saved notebook now draws only the end of each long text output.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

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

coderabbitai Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6f76178f-1f91-4c67-ace7-d3202294f0ee
📥 Commits

Reviewing files that changed from the base of the PR and between fb5d016 and 9ed05a0.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • src/renderer/src/components/editor/IpynbCellOutputs.tsx
  • src/renderer/src/components/editor/IpynbCellRun.tsx
  • src/renderer/src/components/editor/IpynbRendering.test.tsx
  • src/renderer/src/components/editor/ipynb-kernel-outputs.ts
  • src/renderer/src/components/editor/ipynb-output-text-view.test.ts
  • src/renderer/src/components/editor/ipynb-output-text-view.ts
  • src/renderer/src/components/editor/ipynb-parse.ts
  • src/renderer/src/components/editor/useIpynbCellExecution.test.tsx
  • 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
  • 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.

@nwparker

Copy link
Copy Markdown
Contributor

Closing as superseded by #28967 (and #27721 is taking the retention approach). Thanks: the measurements here are what showed the cost of keeping full output.

@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