Issue #2282: for e in yaml::Yaml::events(input) { ... } (the events bench with the walk…

Open and answer this issue on GitHub.

blocked, bugs, yaml · opened 2026-11-19 · updated 2026-11-20 · 15 comments

Filed by the driver from the Found: of the run of issue-1548-rerun (#1548) (owner, 2026-11-06).

Found

for e in yaml::Yaml::events(input) { ... } (the events bench with the walk moved into fn lines(input: Bytes) -> String throws) prints the same events as yaml::events(yaml::documents(input)) but counts 40,360M instructions on target/yaml-bench/inputs/deep.yaml against 340.3M, and 5,464M against 278.3M on scalars.yaml; it should cost about what the in-memory parse costs (ADR-grammar-2 D7 streams so as not to hold the whole input); traced: winnow_grammar rt/stream.rs Stream::record_chunk (39.6G of 40.4G inclusive) parses the rule’s prefix again in the diagnosing pass, and the yaml rule’s prefix Opened Bom? Blanks DocEnd* FirstEvents(limits.depth) holds the whole first document (malloc/free 60%, ParseError::push_rule 11.7%); suspected that a grammar whose first document is a fold item as well avoids it (check: that rule shape, callgrind on deep)

To build

Done when

The probe or check gives the expected output the first item names from its ADR or Part I-III section, and a tests/compiler/tests/ test (or the named check) that failed on the unfixed tree is green; or the probe already passes on develop and a test pins it, naming the commit that fixed it; or the issue is closed as by design, naming the function or ADR.


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-19

Brief queued: issue-2282


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2282

Your work order is issue #2282, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2282/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/yaml/issue-2282.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-19

Run: issue-2282, Result: blocked

Tokens: input 116, cache read 3855038, cache write 89864, output 26890 Cost: 2.08 USD, time 13 min 34 s, turns 58

Report

Result: blocked Files: none Commit: none Body: Reproduced on HEAD 7062787d7 (target/fast/nikaia fresh): for e in yaml::Yaml::events(input) inside fn lines(input: Bytes) -> String throws prints the same lines as the events bench, 3.96 s against 0.065 s on deep.yaml and 0.56 s against 0.044 s on scalars.yaml (opt-level 3, lto). On the first 4 items of deep.yaml (21,684 bytes) callgrind counts 8.86M for the in-memory events(documents(input)), 833M for the same input with ]]]bad: [ appended (the in-memory parse fails, so it runs winnow-grammar’s diagnosing pass), and 861M for the stream. So the stream’s cost is the diagnosing pass. That pass costs about 95 times the fast pass on this grammar: _int_malloc/_int_free/malloc/free come to 60 %, and ParseError::push_rule (11.8 %) turns each rule name into a String for every failure frame (rule_stack: Vec<String>, winnow-grammar src/error.rs:244). winnow-grammar’s Stream runs that pass on every matched prefix (run -> record_chunk, src/rt/stream.rs:888 at rev e1dd687) and again on the last item of a fold when the fold ends (settle Stop::Ended -> replay_prev). The parse in memory runs it only on a failure. Both are in the external winnow-grammar crate (pinned rev e1dd687), which no builder can change or re-pin. Nothing in Nikaia (emitter, yaml grammar) can fix it without a decision. Pushed: none Tests: none run (nothing changed); probes: the stream program built with $S/old/nikaia == HEAD; in-memory vs stream outputs cmp-identical on small, scalars and deep Gate: green Deviation: none Found: @stream streaming costs as much as winnow-grammar’s diagnosing pass, about 95 times the fast pass: on the first 4 items of target/yaml-bench/inputs/deep.yaml (21,684 bytes), callgrind counts 861M for for e in yaml::Yaml::events(input) {...} and 8.86M for yaml::events(yaml::documents(input)), and 833M when the in-memory parse fails (]]]bad: [ appended, so its diagnosing pass runs); it should cost about the in-memory parse (ADR-grammar-2 D7: a stream so the whole input need not be held); traced: winnow-grammar rev e1dd687 src/rt/stream.rs Stream::run calls record_chunk (diagnosing replay) after every matched prefix, and settle Stop::Ended replays the last fold item diagnosing; the pass itself is dominated by malloc/free (60 %) and ParseError::push_rule cloning each rule name into rule_stack: Vec<String> per failure frame (src/error.rs:244); the fix is in winnow-grammar (e.g. a &'static str rule stack, or a stream over an in-memory Bytes that diagnoses only on failure by parsing again from the start), no decision yet Found: a @stream entry with two repetitions, in a program where another function’s default argument is computed at build time, gets a misleading NK1127 instead of the @stream refusal: struct Lim { depth: i64 } fn default_lim() -> Lim { return Lim { depth: 3 } } grammar G { rule WS = "" -> { } @stream entry rule items(lim: Lim = default_lim()) -> i64 = A(lim.depth)* B(lim.depth)* eof rule A(left: i64) = "a" -> { emit left } rule B(left: i64) = "b" -> { emit left + 1 } } fn count(input: ref Bytes; lim: Lim = default_lim()) -> i64 { return lim.depth } fn main() throws { let b = Bytes([97, 98]) for x in G::items(b) { println(x) } println(count(b)) } prints error[NK1127]: lim can't be computed while the program is built ... This compiler couldn't build the program that computes it, which is this compiler's fault at count’s default; without count the same program prints the real refusal The compiler can't translate this @stream entry: its body has to hold one repetition of a rule, which it should print in both cases; suspected: comptime_bundle.nika builds the bundle from the program and turns the emitter’s refusal into CheckWall::DidNotBuild (check: the bundle build’s stderr for this probe) Needs: supervisor decision Changelog: none Issue: wrong I7: making the first document a fold item does not help. Measured with one fold NextEvents(limits.depth)* that also takes a bare first document: 3.996 s on deep and 0.46 s on scalars, against 3.96 s and 0.56 s before, and 876M against 861M on the 4-item deep input, because a fold’s end still replays its last item diagnosing (Stream::settle Stop::Ended -> replay_prev). Also broke I7: the Found named no file or function where the fix lives, which is the external winnow-grammar crate, outside Nikaia Owner: should winnow-grammar’s diagnosing pass get cheaper (a rule stack without a String per frame), or should a stream over an in-memory input diagnose only on failure, by parsing again from the start as Diagnose::Replay does in memory? Comment: none Friction: none Disk freed: 8M scratch; target/nikaia-project-tests 997M, / 7.5G free of 252G (81 %), no cache entry over 100 MB created Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDveRM5qKZKyCqq6Y24

Debrief

  1. Most turns: testing the issue’s guess that making the first document a fold item would fix it. My first variant broke the build with an NK1127 “this compiler’s fault” error. Finding out what was behind it took about 8 turns: looking for the build-time main.rs and writing two smaller probes. It turned out to be a hidden @stream refusal (only one repetition is allowed). Each build of a variant cost about 1.5 minutes.
  2. Lookups the brief could have handed me:
    • rt/stream.rs is in the external winnow-grammar crate, under /root/.cargo/git/checkouts/winnow-grammar-*/<rev>/.
    • A @stream entry may hold only one repetition.
    • The bench builds with opt-level 3 and lto, and its inputs are in target/yaml-bench/inputs.
  3. Checks run:
    • Useful: timing of the stream and in-memory programs, a cmp of their outputs, one callgrind run on a small slice of deep.yaml, the in-memory parse on deliberately broken input, and the single-fold variant.
    • Wasted: the two-fold variant (refused by design), the hunt for the build-time main.rs, and where.nika -- NK1127, which crashed on a non-text .stdout.
  4. Change that would save the most: builder.md should say that a cause traced into an external crate (winnow-grammar) is outside the repository. The run should then give one confirming measurement and report blocked, without trying grammar workarounds.
  5. What the issue lacked:
    • broke I7: it named no repository or path for Stream::record_chunk (winnow-grammar, rev e1dd687).
    • wrong I7: the suspected fix (first document as a fold item) does not help, because the fold’s end replays its last item through the slow error pass.
    • rules-gap: no rule asks an issue to compare against the in-memory parse on failing input. That one comparison shows the cost is the error pass itself.
    • knowledge: Grammar | A @stream entry's body holds exactly one repetition; a second one is refused, and NK1127 can hide that refusal when another function has a default computed at build time.
  6. Traps for the next builder:
    • Fact: Grammar winnow-grammar is an external crate pinned by rev in Cargo.toml; its source is in /root/.cargo/git/checkouts/winnow-grammar-*/<rev>/src (a clone is at /home/user/winnow-grammar), and no builder can change or re-pin it.
    • Fact: Grammar A stream entry runs winnow-grammar’s error-tracking pass on every matched step and on a fold’s last item, so its cost equals the in-memory parse of a failing input, not of a valid one.
    • Fact: Probes scripts/where.nika -- NKnnnn crashes with NotText on tests/compiler/tests/print_bytes_writes_them_unchanged.stdout; grep the NK code instead.

Generated by Claude Code

keywan-ghadami, 2026-11-19

The report of the run of issue-2282 (#2282) judged this issue against docs/issues.md; the author fixes the issue by the rule it names (How a run judges its issue):


Generated by Claude Code

keywan-ghadami, 2026-11-19

Driver: not queued, this issue waits for #2293, #2294, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

keywan-ghadami, 2026-11-20

Unblocked (supervisor, 2026-11-20). The cause in winnow-grammar is fixed by the fix for #2293: Nikaia pins winnow-grammar a88e9a6 on develop since 230f321f. “A @stream entry with two repetitions…” (#2294) is not a prerequisite. It is a misleading NK1127 diagnostic and does not hold up this issue.

Measured with callgrind after the pin:

Input Stream before Stream now In-memory events(documents(input))
deep.yaml 40,360M 775M 221M
scalars.yaml 5,464M 547M 254M

The output is identical to the in-memory parse.

Left for this issue, in the yaml grammar. On deep.yaml the stream still costs 3.5× the in-memory parse. 641M of the 775M is the fast pass of the prefix step Opened Bom? Blanks DocEnd* FirstEvents(limits.depth). The first document sits in that prefix, so it is parsed again each time the window grows (the reader doubles the window and parses the step again).

The earlier run’s measurement against making the first document a fold item no longer holds: it failed because a fold’s end replayed its last item through the diagnosing pass, which winnow-grammar no longer does. Measure that shape again first.

To build

Done when

The stream costs about what the in-memory parse costs on deep.yaml and scalars.yaml (figures from callgrind in the commit message), the output is identical, and the test is green.


Generated by Claude Code

keywan-ghadami, 2026-11-20

Brief queued: issue-2282


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2282

Your work order is issue #2282, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2282/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/yaml/issue-2282.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-20

Run: issue-2282, Result: partial: the stream on deep.yaml still costs 3.3x the in-memory parse (586M vs 177M), scalars 1.85x (407M vs 220M); the rest lies in winnow-grammar (Found), not in Nikaia

Tokens: input 146, cache read 5982692, cache write 110443, output 41149 Cost: 2.96 USD, time 1 min 41 s, turns 73

Report

Result: partial: the stream on deep.yaml still costs 3.3x the in-memory parse (586M vs 177M), scalars 1.85x (407M vs 220M); the rest lies in winnow-grammar (Found), not in Nikaia Files: crates/nikaia-std/src/compiler/emit_grammar.nika crates/nikaia-std/src/compiler/emit_core_leaves.nika crates/nikaia-std/src/compiler/lowered.rs crates/nikaia-std/src/compiler/lowered/emit_core_leaves.rs crates/nikaia-std/src/compiler/lowered/emit_grammar.rs tests/compiler/tests/a_stream_walk_takes_an_item_longer_than_a_reader_frame.nika tests/compiler/tests/a_stream_walk_takes_an_item_longer_than_a_reader_frame.stdout packages/yaml/tests/events_stream_whole_input.nika packages/yaml/tests/events_stream_whole_input.stdout Commit: A walk of a @stream entry reads its in-memory input in one block, with no frame bound Part: #2282 Body: A Nikaia walk over a String/Bytes passed winnow_grammar::rt::Reading::default() (1 MiB blocks, 16 MiB frame), so a document at the end of the input was parsed again at each doubled window, and a single item or prefix over 16 MiB ending at the input’s end was refused (“raise Reading::max_frame”, which Nikaia cannot) where yaml::documents parses it. emit_walk_reading (emit_grammar.nika), used by emit_stream_walk and emit_core_grammar_entry, now passes block = len+1, max_frame = len. Callgrind (bench nikaia.toml settings, outputs identical to events(documents(input)) on small, deep, scalars, large and a 20 MB document): deep 586.4M -> 586.3M (in memory 177.4M), scalars 498.4M -> 406.8M (219.7M). The first To build item measured: the single fold that also takes the first document gives deep 586.3M, scalars 499.0M, the same as today, because deep.yaml and scalars.yaml are each one document, so the document is the whole step either way. Memory: the engine’s buffer now holds a copy of the input (the walk already held __wg_source, a copy). Pushed: local 06cda3996b961afd94e6802f1f7a42bc4a937362 Tests: a_stream_walk_takes_an_item_longer_than_a_reader_frame (new; failed before: “the parse looked more than 16777216 bytes ahead”, green after, –both-settings) and the 6 other a_stream* compiler tests green; packages/yaml events_stream and events_stream_whole_input (new; several documents event- and span-identical to the tree’s walk, and a 17.9 MB document; failed before on the long one) green; lower-std fixpoint clean; cargo fmt, pre-push green; no clippy (only a string literal in two lowered files changed) Gate: green Deviation: none Found: winnow-grammar 138bfa2 src/rt/stream.rs Stream::run (traced): with a zero-sized state (lazy), a step whose fast attempt touches the end of the window is rolled back and parsed again after the next read even when that read returns 0 bytes (eof, window unchanged), so the last document of every stream is parsed twice: callgrind on target/yaml-bench/inputs/deep.yaml (one document, 1,008,472 bytes) through for e in yaml::Yaml::events(input) { out.push_str(yaml::event_line(e)) } shows yaml::Yaml::__edge_parse_AnyDoc_inner called 2x (385.6M) under Stream::attempt, against one YamlOverBytes::parse_AnyDoc_inner (110.4M) for yaml::documents; it should be one parse, the result of the touched attempt standing when the read after it adds nothing and hits eof (the module doc: a touched result is thrown away only because more input could change it); also each edge-tracked AnyDoc parse costs 192.8M against the plain 110.4M on deep (suspected: the edge wrapper around every parser, src/rt/stream.rs edge/edge_reach, settle with a callgrind of a grammar built without #[stream]); no decision yet whether winnow-grammar or the Nikaia emitter should hand an in-memory input to a non-reader entry Needs: a winnow-grammar change for the Found’s twice-parsed last step (outside Nikaia, no GitHub access here) Changelog: A walk of a @stream entry over a String or Bytes reads it in one block and no longer refuses an item longer than 16 MiB at the input’s end; yaml’s Yaml::events on a 2 MB document costs 18% fewer instructions. Issue: wrong I7: the supervisor’s comment holds that the first document in the prefix is parsed again as the window grows and that a fold item would avoid it; deep.yaml and scalars.yaml hold one document each, the fold shape measured 586.3M/499.0M against 586.4M/498.4M, and the re-parses come from the 1 MiB reading windows (fixed) and the eof re-parse in winnow-grammar Stream::run Owner: none Comment: none Friction: tests that spawn the toolchain (a_stream_entry_of_another_package_is_walked) fail when run from a binary not named exactly nikaia (I ran $S/new-nikaia), as Core says; cost one rerun Disk freed: scratch probes removed; target/nikaia-project-tests 2.0G, / 17G free; new cache entry over 100 MB: rust-library-user/69f15174 (1031 MB) Reviewed: 9921eba410048a58c790185267ebe6ad05cabef01532ffbc4cb7ff65f007a22e Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwSpspVvrTQMgwWNUS

Debrief

  1. Most time: waiting on builds. That was the compiler rebuild for the winnow pin (3.5 min), the yaml bench package rebuilds (about 1 min each, five times), the lower-std cycle, and a 17.9 MB yaml probe built without optimisation (34–60 s). Reading winnow-grammar’s stream.rs to find where the stream parses again was the main thinking cost.
  2. Lookups the brief could have handed me: where the yaml bench lives and how it is built (target/yaml-bench/events/nikaia.toml holds the settings), the program the Found measured (the lines form), and that deep.yaml and scalars.yaml are each one document. Also the path of the winnow-grammar checkout (~/.cargo/git/checkouts/.../138bfa2), the Reading defaults (1 MiB read, 16 MiB frame), and the catch + error binding syntax.
  3. Checks run: callgrind of the in-memory and stream programs before and after, a fold-shape experiment, the compiler a_stream* tests, the yaml events_stream* tests, the lower-std cycle, fmt and pre-push. Wasted: one compiler test run from a binary named new-nikaia, which made 3 tests fail falsely. Also one probe where I put catch e, which is not the syntax, plus a rebuild for it.
  4. One change: the issue (or brief) should give the measurement command and the program it measured, and say how many documents each input holds. With that, the fold hypothesis falls in one grep -c '^---' instead of a build-and-measure experiment.
  5. What the issue lacked:
    • wrong I7: the supervisor’s cause (the first document in the prefix, reparsed as the window grows; a fold would avoid it) does not hold. Both inputs are one document, and the reparses come from the 1 MiB reading windows and from winnow’s reparse at end of input.
    • broke I5: there is no probe snippet. The bench program is named only in prose.
    • knowledge: Measuring | the yaml-bench inputs deep, scalars and large are each a single document, so stream-versus-memory costs on them measure the parse of one step, not the fold.
  6. Traps the next builder will meet:
    • Fact: Measuring | A Nikaia walk of a @stream entry hands winnow-grammar a slice through Read, so with the unit state the last step is parsed twice (once before the read that returns 0), whatever the reading block.
    • Fact: Core | nikaia test runs whose tests spawn the toolchain must use a copy named exactly nikaia ($S/new/nikaia), or they fall back to target/fast/nikaia and fail falsely.
    • Fact: Probes | a caught error is bound as error inside a plain catch { } (catch e { } is a parse error).

Generated by Claude Code

keywan-ghadami, 2026-11-20

The report of the run of issue-2282 (#2282) judged this issue against docs/issues.md; the author fixes the issue by the rule it names (How a run judges its issue):


Generated by Claude Code

keywan-ghadami, 2026-11-20

Brief queued: issue-2282-rerun


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2282

Your work order is issue #2282, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2282/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/yaml/issue-2282-rerun.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-20

Run: issue-2282-rerun, Result: partial: deep.yaml still costs 1.9x the in-memory parse (stream 337.3M, in memory 177.4M); scalars.yaml is at 1.08x (236.6M against 219.7M), which counts as about the in-memory cost; what is left lies in winnow-grammar’s edge-tracked parse, outside Nikaia

Tokens: input 90, cache read 3275793, cache write 100366, output 20095 Cost: 1.91 USD, time 7 min 55 s, turns 45

Report

Result: partial: deep.yaml still costs 1.9x the in-memory parse (stream 337.3M, in memory 177.4M); scalars.yaml is at 1.08x (236.6M against 219.7M), which counts as about the in-memory cost; what is left lies in winnow-grammar’s edge-tracked parse, outside Nikaia Body: Measured with callgrind on develop c0d73400, winnow-grammar ce68d22, bench settings (opt-level 3, lto, codegen-units 1). Stream program: fn lines(input: Bytes) -> String throws { let mut out = String(); for e in yaml::Yaml::events(input) { out.push_str(yaml::event_line(e)); out.push_str("\n") }; return out }. In-memory program: yaml::events(yaml::documents(input)). Outputs are identical on small, deep, scalars and large. Deep breakdown: the one edge-tracked parse of the step, Yaml::__edge_parse_AnyDoc_inner under Stream::attempt, costs 191.5M against 110.4M for YamlOverBytes::parse_AnyDoc_inner in memory (+81M). EmitSink::push is 14.9M and the channel about 10M. Ruled out: (1) the fold shape (earlier run: both inputs are one document each); (2) walking the bytes copy of the grammar, which ADR-grammar-input-v1 D1 would call for over a Bytes input. With the walk in the yaml package, the emitter already calls YamlOverBytes::parse_events_reader_each, and that costs more: deep 359.3M, scalars 279.1M. (3) Nikaia’s emitter cannot skip the tracking: winnow-grammar generates only parse_<rule>_reader_each for a #[stream(each)] rule, with no in-memory driver that runs the plain copy. The test pinning a stream of several documents already exists: packages/yaml/tests/events_stream_whole_input.nika (commit “A walk of a @stream entry reads its in-memory input in one block, with no frame bound”). Nothing committed. Pushed: none Tests: none run besides the callgrind measurements and output comparisons above (no code changed) Gate: green Deviation: none Found: winnow-grammar ce68d22 winnow-grammar-macros/src/codegen/stream.rs (traced): a #[stream(each)] rule has only the reader driver parse_<rule>_reader_each, which runs every step through the tracked copies (__edge_parse_* with EdgeEmpty, Stream<Text, &[u8], (), true>) even when the whole input is in memory (Reading block = len+1). On target/yaml-bench/inputs/deep.yaml, for e in yaml::Yaml::events(input) { out.push_str(yaml::event_line(e)) } parses its one document in 191.5M (Yaml::__edge_parse_AnyDoc_inner, called once) against 110.4M for the plain YamlOverBytes::parse_AnyDoc_inner of yaml::documents(input); the whole program costs 337.3M against 177.4M. It should cost about the plain parse (ADR-grammar-typed-read-v1 D7 streams only so as not to hold the whole input). Suspected fix: an in-memory each-driver, or a Stream that knows eof at the start and runs the plain copy per step. no decision yet on whether winnow-grammar or Nikaia’s walk (emit_stream_walk in emit_grammar.nika, emit_core_grammar_entry in emit_core_leaves.nika) should use it Needs: a winnow-grammar change (an in-memory driver for a #[stream(each)] rule that runs the plain copy), outside Nikaia, no GitHub access here Changelog: none Issue: wrong I7: the supervisor’s 2026-11-20 To build blamed the first document in the prefix and proposed a fold item. After ce68d22, scalars is at 1.08x, and deep’s 1.9x is the cost of the edge-tracked parse of its single document (191.5M against 110.4M), which no grammar shape removes; broke I7: the fix lives in winnow-grammar, which the issue does not name Owner: none Comment: none Friction: none Disk freed: scratch builds removed (about 3 GB); target/nikaia-project-tests 2.0G, / 4.7G free; no new cache entry over 100 MB Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwSpspVvrTQMgwWNUS

Debrief

  1. Most time: two scratch builds of the yaml bench (about 1.5 min each), callgrind runs, and reading winnow-grammar’s generated code and stream codegen. The bytes-copy experiment (a whole package copy plus a build) disproved its hypothesis but cost the most.
  2. Lookups: the earlier run’s scratch projects and measure.sh, which I found by searching the scratchpad and should have been in the brief. Also the winnow-grammar checkout path, ADR-grammar-input-v1 D1/D2, the fact that emit_core_leaves already picks OverBytes for a same-package walk, and that the generated yaml Rust lives in target/nikaia/gen/yaml/yaml.rs.
  3. Checks: callgrind of mem and stream (needed), the inpkg bytes-walk measurement (useful as a ruled-out path), and the tree view of attempt (useful). Wasted: the --tree=caller view of the edge Blanks, whose LTO-folded symbols were meaningless. Also, my report says “Disk freed: about 3 GB”, but du showed only 82M in the scratchpad. That figure is wrong, not measured.
  4. One change: a rerun brief should give today’s figures, the measurement script and the two programs. I would then have seen in one turn that scalars was already done and that deep’s gap is the one tracked parse.
  5. What the issue lacked:
    • wrong I7: the comment’s cause (the prefix re-parsed as the window grows; a fold item avoids it) no longer held after ce68d22.
    • broke I7: the issue names no file or function for the remaining cost, which is winnow-grammar’s tracked copies (codegen/stream.rs).
    • broke I5: there is no probe snippet; the bench programs are named only in prose.
    • knowledge: Measuring | the yaml-bench inputs deep, scalars and large are each a single document, so stream-versus-memory costs on them measure one step's parse, not the fold.
  6. Traps:
    • Fact: Measuring | Under LTO, callgrind attributes folded identical functions to one symbol (an edge Blanks "called" from Sender::send), so exclusive costs of small generated parsers are unreliable; compare inclusive costs of whole rules.
    • Fact: Lowering and lower-std | A walk of a @stream entry over Bytes in another package always uses the text grammar (_nikaia_walk__` calls `::`), while one in the same package uses `OverBytes`; over bytes the tracked stream costs more.`

Generated by Claude Code

keywan-ghadami, 2026-11-20

The report of the run of issue-2282-rerun (#2282) judged this issue against docs/issues.md; the author fixes the issue by the rule it names (How a run judges its issue):


Generated by Claude Code

keywan-ghadami, 2026-11-20

Waits for #2420 (an in-memory driver for a #[stream(each)] rule in winnow-grammar, built by the supervisor session). The second run brought the stream to 337.3M on deep.yaml (in memory 177.4M) and 236.6M on scalars.yaml (in memory 219.7M); the rest is the edge-tracked copy that every step runs through even when the whole input is in memory.

Needs #2420


Generated by Claude Code

keywan-ghadami, 2026-11-20

Now waits for #2433 (the per-event thread handoff of a walk); #2420 is done: the stream on deep.yaml went from 277.0M to 217.7M, on scalars.yaml to 127.5M (in memory 125.0M).

Needs #2433


Generated by Claude Code

keywan-ghadami, 2026-11-20

Now waits for #2435 (the engine’s emit path in winnow-grammar); #2433 is done (deep.yaml stream 212.2M).

Needs #2435


Generated by Claude Code

keywan-ghadami, 2026-11-20

Open point moved here from the closed improve issue #2413 (Found: #2412): the winnow-grammar change for the twice-parsed last stream step belongs to this work.


Generated by Claude Code

Back to Open Issues