Issue #2419: winnow-grammar picks an alternative by the first byte where the alternatives’ first bytes are disjoint

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.

Goal

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.

Today

To build

Done when


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-20

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:

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:

Two directions follow:

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

Back to Open Issues