Skip to content

perf(table): read a node table where it lies, without a JSON value tree - #20

Merged
adammharris merged 1 commit into
mainfrom
agent/backlog-table-decode-without-a-value-tree
Oct 26, 2026
Merged

adammharris merged 1 commit into
mainfrom
agent/backlog-table-decode-without-a-value-tree

Conversation

@adammharris

Copy link
Copy Markdown
Member

What changed

table::decode and table::decode_bare read a node table where it lies,
instead of parsing it into a json::Value tree first.

  • json::check_rows makes one pass over the text. It refuses exactly what
    json::parse refuses, and as it goes it gathers the top object's members
    and every row's members as borrowed slices of the text.
  • read walks those two lists and allocates only for what the Document
    keeps. It is generic over a small json::Json / json::Object pair,
    which both &Value and the new json::Raw implement. So from_value
    (public, and still taking a &Value) goes through the same read, and
    the two paths cannot drift.
  • ast::json::read_kind keeps its signature. The new read_kind_in
    serves both kinds of object.
  • The row count is taken only when a row names a parent at or after itself.
    Such a row is refused either way, and the count says which refusal it
    gets. Otherwise counting would cost a pass of its own.

Why

docs/tasks/table-decode-without-a-value-tree.md: every reparse through a
runtime row decodes the language's table, and building the value tree was
most of what a keystroke cost. The task was written against the Zig engine.
The Rust port kept the same shape and the same cost.

bench_edit, i5-8279U, documents cut from this repository's docs:

document compiled key runtime key ratio decode
34 KB, before 0.73 ms 4.19 ms 5.8x 2.30 ms
34 KB, after 0.73 ms 3.04 ms 4.2x 1.30 ms
135 KB, before 2.64 ms 16.17 ms 6.1x 9.63 ms
135 KB, after 2.69 ms 11.36 ms 4.2x 4.90 ms

Task

This advances the task and does not close it. Its status moves to
in-progress, and it now records the numbers above. The done-when's 3x
can't be reached by the decode alone. On the 34 KB document, 3x leaves
about 0.5 ms to decode a 220 KB table. But building the Document from
rows already in hand costs 0.44 ms, and one checking pass over the text
costs about 0.4 ms. Reaching 3x needs a cheaper encode or a smaller table,
or the target has to be relaxed, and the task now says that choice is open.

Verification

  • New tests: decode_in_place_agrees_with_the_parsed_value (about 70
    hand-picked texts: malformed JSON, escapes in keys and strings, duplicate
    keys, floats, out-of-range integers, the nesting limit, invalid UTF-8,
    every refusal read makes) and decode_in_place_agrees_on_damaged_tables
    (4,000 one- or two-byte mutations of a real table). Both hold decode and
    decode_bare to the same Document and the same Problem as
    json::parse followed by the value-tree reader. Each catches a planted
    bug in the number reader.
  • The existing tests in table.rs and runtime.rs pass unchanged.
  • ship ci: test, cli-wasi, capi and version pass. The typescript job skipped itself (no npm ci in bindings/typescript here), so GitHub CI is the first run of it.

decode and decode_bare check the text in one pass and gather the top
object's and each row's members as borrowed slices, then read the rows
from those lists. from_value goes through the same reader over a parsed
Value. On a 34 KB djot document a keystroke through the runtime row drops
from 5.8x to 4.2x the compiled row's; the task stays in progress, since
3x is out of reach by the decode alone.
@adammharris
adammharris merged commit 5ec90e3 into main Oct 26, 2026
5 checks passed
@adammharris
adammharris deleted the agent/backlog-table-decode-without-a-value-tree branch October 30, 2026 01:25
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