Skip to content

fix: streaming stays linear with JSX in code, five frames that drew otherwise, a crate abort on wide tables - #1

Merged
rsaryev merged 4 commits into
mainfrom
fix/streaming-block-split
Nov 21, 2026
Merged

rsaryev merged 4 commits into
mainfrom
fix/streaming-block-split

Conversation

@rsaryev

@rsaryev rsaryev commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

What changes for a person using it

A reply about React streams in linear time again. A tag that only code leaves open (a render prop, whose => the cut read as the end of an open <List tag; an <li> an HTML snippet leaves to the parser; a <!-- in a template) made the rest of the reply one block, read and drawn again whole on every token. Measured in Chrome on two cores, with the published 0.7.1 against this branch:

Stream 0.7.1 this branch
one render-prop fence, then 80k characters 54,136 ms, updates up to 66 ms 808 ms, up to 15 ms
the same 80k without the fence 873 ms 903 ms
markdown-to-jsx's README, 80k, 20-character frames 12,977 ms, 20 frames over 16 ms 1,222 ms, none
the same, 6-character tokens stopped at 93% after 30 s 2,420 ms

On that README 0.7.1 lost to markdown-to-jsx (11,190 ms); this branch is 9× faster than it. The drawn page is the same (2,524 nodes, the same text).

Five frames of a stream drew differently from the finished reply, found while checking the cut against one parse (one by a reviewer, three by the block fuzz once its lines held code that looks like tags, one by the golden digest):

  • a closing tag in code (</details> in an example) ended the HTML block around it, and the text after it was drawn outside the <details>;
  • a fence still being written left out its file name (data-title) on React, on the page and in <flow-down>;
  • tabs whose heading came after a blank line under a lone $$ lost the block after them;
  • an item that opened empty was read as holding the indented code under its blank line;
  • a closing tag with nothing open (a second </div>) closed the tag opened after it.

While a reply streams, the row of dashes under a header (|--), a footnote reference being typed ([^1) and a task's box before its first word (- [x) are held back for a token or two instead of showing as text (docs/streaming.md).

The Rust crate no longer aborts on a wide table. A row's cells are made before their text is read, and the reckoning of room for the nodes to come took them as the text's: 500 columns over 20 KB reserved 12 million nodes, and the worst bench's short-rowed table at 112 KB asked for 69 GB, which aborts the program (R1, R7). That table now grows 3.9× at four times its length, where it grew 8.5×; the parse bench is as it was (90 allocations, 4.4 MB, the same ratio to pulldown-cmark). The product is saturated for the 32-bit wasm build.

Commits

  1. fix(stream): a fence's code is code to the cut (markupOf, from what the scan already knows), the empty item, the tabs over a blank line, the stray closing tag, data-title on a growing fence; the fence checks written four times over are two helpers.
  2. fix(heal): the three held-back ends.
  3. bench: react-10k / react-40k and the linear-code rule. The corpus had no code that looks like markup, which is why linear never saw this. On main the pair streams at n^2.02, here at n^0.57.
  4. fix(crate): the room reckoning, with a test.

Checked

  • bun run test: 921 pass. FUZZ=300000 bun test blocks-fuzz: 4 sweeps, 1.2 million documents, none differ from one parse. CODE_TAG_LINES is a sweep of its own, so the documents the golden digest holds are unchanged.
  • Golden digest, moved only for output meant to change, and every move checked against one parse:
    • commit 1: 182 streaming digests of documents with a titled fence still open, all 546 of their prefixes now drawing what one parse draws;
    • commit 2: 43 streaming digests, every changed prefix one of the three held-back ends (34 boxes, 10 references, 1 row of dashes).
      No other way of drawing (tree, react, remark, tui) moved.
  • bun run typecheck, lint, format:check, build, check, size; site/: npm run check.
  • Size: 0.2 KB more on the entries that cut and heal a reply, 0.1 KB on tui and remark; budgets raised by that, with the reasons in scripts/size.ts, after the fence checks were folded into two helpers to bring it down from 0.4 KB.
  • The crate: cargo fmt --check, clippy -D warnings (crate and bench), cargo test --locked (82), cargo doc -D warnings, the package's file list.
  • Before and after on the old and new code in turn (--quick --runs=5, two cores): chat-5k 46/41 → 44/37 ms, answer-20k 114/117 → 137/114 ms, within this machine's noise; long-100k 543 → 518, code-50k 208 → 151.

Not checked here, for review

  • The wasm build of the crate: its target cannot be fetched on this machine. CI's rust.yml builds it.
  • results/latest.json has no rows for react-10k / react-40k, so bun run --cwd bench bench:check reports linear-code uncovered until bun run bench runs on the machine the published figures come from (two minutes). I did not commit numbers from this 2-core VM over the M5's.
  • Left as they were, by design: a header row (| A | B |) shows as text until its row of dashes starts, as a line of pipes may be prose; a complete [^1] shows until its definition arrives at the end of the reply. And an HTML tag genuinely left open outside code (<details> with no </details>) still keeps the rest of the reply one block, as one parse reads it so.

Generated by Claude Code

rsaryev and others added 4 commits November 21, 2026 03:34
…se reads otherwise

A tag that only code leaves open joined every block after its fence: `htmlOpen` read the raw
text of the pieces, fences and all, and took a render prop's `=>` for the end of an open `<List`
tag, an `<li>` a snippet leaves to the parser for one that never closes, a `<!--` in a template
for an open comment. The rest of the reply was then one block, read again whole on every token:
80,000 characters after one such fence streamed in 54 s in Chrome on two cores, 0.8 s now. A
piece that opens with a fence is code to the cut (`markupOf`), as the scan already knows it is,
and a closing tag in code no longer ends the HTML block around it (`</details>` in an example
drew the text after it outside the `<details>`).

Four more places a block-by-block draw differed from one parse, three found by the fuzz once its
lines held code that looks like tags (CODE_TAG_LINES, a sweep of its own so the documents the
golden digest holds stay the same):

- an item that opens empty holds at most one blank line: the indented code under that line, and
  the fence under it, are not in it;
- a tabs marker's heading under a blank line in the same piece (a lone `$$` above keeps the scan
  from cutting there) is read as the marker's, so the blocks after it stay in the last tab;
- a closing tag with nothing open is dropped, as the HTML parser drops it, and does not close
  the tag opened after it;
- a fence still being written, drawn by its own path, now names its file on its `<code>`
  (`data-title`) as a finished one does, on React and on the shared renderer.

The golden digest moves for that last one only: 182 streaming digests of documents with a titled
fence still open, every prefix of which now draws what one parse draws (checked, 546 prefixes).
The opening and closing checks of a fence, written four times over, are two helpers. Size: 0.2 KB
on the entries that cut a reply, with the reasons in scripts/size.ts.

Checked: `bun run test` (921 pass), `FUZZ=300000 bun test blocks-fuzz` (4 sweeps), golden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qcwzcvC2yxKDfLTRyCg6U
…hey mean something

Three ends of a stream showed their syntax as text for a token or two before it turned into
what it is:

- the row of dashes under a table's header (`|--`, `| --- | -`) printed under the header, and
  both became a table a token later. It is held back while it is the line being typed, under a
  line with a pipe in it: a row of dashes is never prose;
- a footnote reference being typed (`See[^1`) printed `[^1`: `[^` opens nothing but a reference,
  so it is hidden until its `]`, outside a code span;
- a task's box before its first word (`- [x`) was an item reading "[x": it is the item's marker,
  held back as a bare `-` is.

The header row on its own still shows as it comes, as before: a line of pipes may be prose. A
reference that is complete still shows until its definition arrives at the end of the reply.

The golden digest moves for streaming frames only, 43 of them, every changed prefix one of these
three (34 boxes, 10 references, 1 row of dashes) and each drawing what one parse of its healed
text draws. docs/streaming.md lists the three. The changeset covers this and the commit before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qcwzcvC2yxKDfLTRyCg6U
The corpus had no code that looks like markup, so a cut that read a render prop as an open tag
was never measured: `answer-10k` to `answer-40k` stayed linear while a reply about React went
quadratic. `react-10k` and `react-40k` are `answer`'s parts with three shapes of such code (a
usage example whose render prop has its `=>` inside the tag, a component with the same deeper in,
an HTML snippet with an `<li>` left open), and `linear-code` holds their exponent under 1.25, as
`linear` does `answer`'s. The stream-split sweep reads `react-10k` too.

On this branch's parent the pair streams at n^2.02 (274 ms, then 4,493 ms; its last block grows
to 39,369 characters); with the fix at n^0.57 (118 ms, 259 ms; 1,573). Two cores, `--quick`.

results/latest.json has no rows for the pair yet, so `bench:check` reports the rule uncovered
until `bun run bench` runs again on the machine the published figures come from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qcwzcvC2yxKDfLTRyCg6U
…g one no longer aborts

`Inline::fit` reckons the nodes still to come by how many the text read so far made. A row's
cells are made before any of their text is read, and the row's text counted as read only once
the row was done, so the first cell of a wide header, one byte in, reckoned the rest of the
document at thousands of nodes a byte. 500 columns over 20 KB reserved room for 12 million
nodes; the `worst` bench's table with rows short of its columns, at 112 KB, asked for 69 GB and
aborted the program (R1, R7).

The cells now count as the block pass's own, each cell's inlines are reckoned from where it is in
its row, and the guess is held to two nodes a byte still to read: asking too little costs one
more move of the nodes. The product is saturated, so it cannot wrap where usize is 32 bits (the
wasm build). That table grows 3.9 times at four times its length, where it grew 8.5; the parse
bench's allocations (90, 4.4 MB) and throughput against pulldown-cmark are as they were.

Checked: fmt, clippy (crate and bench), `cargo test --locked` (82), docs, the package's files.
Not here: the wasm build, whose target cannot be fetched on this machine; CI builds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qcwzcvC2yxKDfLTRyCg6U
@rsaryev
rsaryev merged commit 90fcef6 into main Nov 21, 2026
4 checks passed
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.

1 participant