Open and answer this issue on GitHub.
wip, yaml · opened 2026-11-20 · updated 2026-11-20 · 1 comment
Filed by the supervisor (owner’s goal, 2026-11-20: yaml faster than saphyr-parser).
Part of #1548.
winnow-grammar picks an alternative by the input’s first byte where the alternatives’ first bytes do not overlap, instead of trying them in turn. This helps every grammar written in Nikaia. Built in winnow-grammar (keywan-ghadami/winnow-grammar) and pinned in Nikaia, as for #2293.
benches/yaml/README.md, Where yaml is behind: the choices of FlowItem and FlowAny and winnow_grammar::rt::expected are 15 % of deep (callgrind, events.off, checks off).rt::first_byte for some alternatives: it appears in the profile of MapEntry.events.off deep and large, list the alternatives of the yaml grammar by inclusive cost. Note which of them first_byte covers in the generated code (winnow-grammar-macros, codegen of alternatives).examples/stream_profile.rs and a yaml profile measured; PR on winnow-grammar.Cargo.toml and both lock files); re-run benches/yaml/bench.nika and update the README table.FlowItem, FlowAny and Block dispatch by first byte where their first sets are disjoint.events.off deep counts fewer instructions.Generated by Claude Code
First measurement (supervisor session, winnow-grammar branch first-bytes-fixpoint, commits 1cf41ae and f15a5ed). Result: no gain for yaml.
What the branch builds. The first-byte sets in first_bytes.rs now reach almost every rule of the yaml grammar:
__nikaia_count(p = " ")).count, empty, eof, any, text, bytes and span are handled.peek(p) fixes the byte, so a cut after it no longer blocks the set (SeqLevel, MapLevel).winnow-grammar’s tests stay 511/511, with new unit tests.
Measured with callgrind on events.off (opt 3, lto, checks off). Outputs are byte-identical:
| Input | Before | After |
|---|---|---|
| deep | 140.61M | 140.45M |
| scalars | 210.82M | 211.86M |
| large | 4,494.95M | 4,500.53M |
Why it does not help. The costly alternatives (Block, Content, Inline, FlowItem, FlowAny, FlowNode, KeyNode) reach a plain scalar early. A plain scalar begins with x:any if(plain_safe(...)), and its first set is every byte, so their sets are full and no guard is written. Where a set is narrow (Seq’s -, KeyTail), the guard costs about what it saves.
The two commits are reverted on the PR branch (keywan-ghadami/winnow-grammar#39, 15047c5) and kept on first-bytes-fixpoint for a grammar where they help.
Where the 15 % of the alternatives does lie. The alternatives repeat work they share:
Block’s three alternatives each run not(Marker) m:__nikaia_count(p = " ") again before their guard.Content and Spaced each try Seq, Map, Propped and so on, which read the same properties and indentation.Two directions follow:
Blanks/Block.I’ll measure (b) next on the profile: how much of Block, Content and Inline is the repeated prefix. This issue stays wip.
Generated by Claude Code