Repository navigation
Markdown: memoise settled blocks, list items and table rows, and measure only changed table rows - #1130
Conversation
…ure only changed table rows During streaming (`Markdown::streaming`), `stream_cached` parses incrementally from the last block cut, but `Renderer` previously rebuilt the `El` subtree of every settled block, list item and table row on every appended token, and `Table::columns` re-ran `rune::text::content_widths` across every settled row whenever a row finished. - Memoise settled blocks in `Renderer::blocks_in`, settled list-item bodies in `Block::List`, closed code cards inside `Block::Code` (`code_frame`), and settled header/body rows in `Block::Table` via `rune::memo::cached`, advancing `next_source` and `next_task` deterministically across hits so `commit::flatten` and Taffy reuse unchanged `FlattenedMemo` subtrees. - Cache per-row unpadded `(natural, fit)` column widths in `ROW_WIDTHS` (`crates/rune-kit/src/markdown/table.rs`) so adding or editing a row calls `rune::text::content_widths` only on the changed row (`O(1)` per row instead of `O(R)`).
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Windows whole suite ( |
…hs, and link_favicon memoisation Address review findings on settled Markdown block/item/row/card memoisation: - Guard `ROW_WIDTHS` and `WIDTHS` lookups and folding by column count (`rw.natural.len() == n && rw.fit.len() == n`) and key both by full 128-bit `PairHasher` digests so a cache collision cannot panic or narrow to 64 bits. - Replace intermediate 64-bit `DefaultHasher` reductions with a 128-bit OS-seeded `PairHasher` (`(RandomState, RandomState)`), and destructure `Renderer`, `Span`, and `Flow` exhaustively so any future field fails to compile until classified. - Precompute each parsed block's, list item's, and table row's 128-bit content digest once at parse time (`PreBlock` / `PreItem` / `PreTable` / `PreRow`) and carry `meta` across `cache::extend` alongside `starts` and `maps`, avoiding per-token text re-hashing and `Vec` allocations across settled blocks and rows. - Hash `link_favicon` (`Pixels` id, dimensions, and generation) into link digests without heap allocation instead of refusing paragraphs or list items with favicons.
…1292) * feat(rune-kit): native code-block soft wrapping and text-wrap icon Add native code-block soft wrapping to `rune-kit::markdown` and the `text-wrap` icon (`icons::TEXT_WRAP`) to `rune-theme-opencode` for `anomalyco/opencode#64545`: - `MarkdownStyle::wrap_code(bool)`, `Markdown::wrap_code(bool)`, and `Markdown::code_wrap(Fn(usize, &str) -> bool)` wrap long lines inside `Renderer::code` via `.by_line().wrap_anywhere().wrap_greedy()` while keeping `#1133` per-line shaping, screen-reader `TextRun` line runs, `#1130` `settled_code_card_digest` memoisation, Find highlights, streaming reveal, `.copy_breaks(2, 2)`, non-mono tab stops, and shell block colours. - Unwrapped blocks (`!wrapped`) remain identical to before. - `Source` computes longest-line tab-expanded stats once at parse time; `CodeFrame::overflows` answers overflow against `text_width - flow.inset` in O(1) on the ASCII monospace fast path (falling back to `rune::text::measure` only near the boundary or for non-ASCII/non-mono). - `CodeFrame::wrapped` reports the block's active wrap state. - `rune-theme-opencode::icons::TEXT_WRAP` adds Desktop's `text-wrap` SVG. * fix(rune-kit): address review #1292 findings (stable body path, lazy exact overflows, lock-free font_epoch, line reuse, scoped memo) * fix(rune-kit): revert paragraphs.rs scope creep, clear ascii/paragraphs on font switch, Acquire/Release font_epoch, bound control chars
stream_cachedparses incrementally from the last block cut during streaming, and this PR wraps settled blocks inblocks_with_dirs, settled non-task list-item bodies inBlock::List(keepingposition_in_set(k + 1, real_n)live on the outerlistitemrow), closed code cards insideBlock::Code(whencode_frameis set), and settled header/body rows inBlock::Tablewithrune::memo::cached(crates/rune-kit/src/markdown/memo.rs). Advancingnext_sourceandnext_taskacross hits keeps later code-card and task indices aligned while the runtime'sreusablecheck reusesFlattenedMemosubtrees.PairHasher, two independent OS-seeded SipHash-1-3 lanes with no 64-bit intermediate narrowing) once at parse time (Rc<PreBlock>,PreItem,PreTable,PreRow, computed iteratively inO(1)call stack up to#1122's511/770bounds) and carrymeta: Rc<[Rc<PreBlock>]>acrosscache::extendalongsidestarts,maps, andeof_deep_tail. WrappingPreBlockinRc<PreBlock>meanscache::extendclones 8-byteRcpointers instead of deep-cloning settledPreBlocktrees per token; settled blocks and rows withoutcode_linkrewrites read their parse-cached 128-bit content digest directly (0text re-hashing and0Vecallocations per token), andRenderer,Span, andFloware destructured exhaustively so adding a field fails to compile until classified.ROW_WIDTHSincrates/rune-kit/src/markdown/table.rs(keyed by 128-bit(u64, u64)withrw.natural.len() == n && rw.fit.len() == nbounds checks) to cache per-row unpadded(natural, fit)widths by(cells, font): measuring (content_widths) runs once per new or edited row, while per-token keying mixes each settled row's cachedPreRowdigest (O(R)fixed-size tuple hashes when the table is still open) and a newly settled row that widens a column changescolsin every row's digest so all rows rebuild with the wider column widths.flowchart LR D["Streamed delta"] --> P["stream_cached + cache::extend / extend_eof_deep_tail<br/>(clone Rc<PreBlock> or rebuild trailing DeepTail spine)"] P --> B{"Block / item / row /<br/>closed card settled?"} B -->|Yes| M["rune::memo::cached hit<br/>(FlattenedMemo + ROW_WIDTHS hit)"] B -->|No: open tail| R["Build & shape open tail;<br/>measure only new table row"]Scope in OpenCode (Rune)'s configuration
OpenCode (Rune) configures
Markdownwithcode_frame,diagram_frame,link_icons+link_favicon,images+image_frame(viapicture_body), zero-captureon_link_tx/on_link_secondary,link_help,reveal,selectable, andscroll_wide:link_favicon, whosePixelsid/size/generation is hashed into the link digest), settled bullet and ordered list items without code/images/interactive tasks, settled table headers and rows (and closed tables as whole blocks), closedBlock::Codeinnercards insidecode_frame,Block::Diff, andBlock::Rule.Block::Codeouter wrapper:code_framebuilds the outer frame and Copy button overlay each commit; only the closed innercardis memoised (and open fences build until closed).Block::Code,Block::Mermaid(withdiagram_frame), orBlock::Image(withimages/on_image) is refused at the enclosing item/block level.diagram_frame) and images (images/on_image): never memoised here (rune-mermaidhas its own scene cache).on_taskwithouttasks_read_only): never memoised as items or enclosing blocks.streamingtofalseat stream end, changing Findhighlights, changing theme, or resizingtext_widthchangesbase_hashand rebuilds every block once.Verification, cache budget, &
#1122(307b2cd7) merge (2ec440b2)"43 of 43 tree checks"verification ran only the standalone review-gate driver (0diff between token-streamed and from-scratch trees) and did not run therune-kittest suite, which is whyrune_kit::markdown::tests::a_stream_drops_the_strings_it_grew_fromslipped at859b23a1.de8cfce0→7ab79a40wrappedPreBlockinRc<PreBlock>and added iterativePreBlock::heap_bytes()(memo.rs+cache.rs:267) counting nested items, childRc<PreBlock>s, table rows, and copied link URLs (0on plain top-level paragraphs, preservinga_stream_drops_the_strings_it_grew_from's formula while bounding list/table/link-heavy replies in the 16 MiB cache).2ec440b2mergesdev307b2cd7(#1122): preservesParsed.eof_deep_tail,BlockMap::DeepTail+ unselectableRole::NoteMoreNestedLinesmarker,QuotePlainCachekey, and511/770iterative bounds; invalidates and rebuildsParsed.meta's trailingPreBlock/PreItemspine incache.rs::replace_eof_deep_tail_metawheneverextend_eof_deep_tailreplaces the tail block whilerender.rs::run_framesthreadsopen_tail(!(self.streaming && is_deep_tail)+!child_open_tail) so nothing on the active tail spine callsrune::memo::cachedand any supersededMemoStoreentry is dropped on commit apply.2ec440b2): all439 / 439existingrune-kittests (0failed,3ignored,a_stream_drops_the_strings_it_grew_fromincluded) passed across all 50 binaries onadais(proof/proof-farm/03eea674-0c60-41eb-99b2-d860eca01c68), andproof/stream/pr1130-gate/summary.json(OPENCODE_RUNE_OTEL=0) passes64 / 64incremental-vs-fresh tree checks (0mismatches) and7 / 7DX12 PNG pairs (0differing RGBA pixels, includingdeep-tail-capstreaming across#1122's 255-list + 64-item cap andextend_eof_deep_tailwith0settled-block rebuilds).