Koru parser defeats exponential backtracking cliffs
Koru has introduced std/parser, a compile-time parser library for its Event Continuation Language that utilizes common-head factoring to eliminate backtracking-induced performance cliffs. By evaluating shared prefixes only once during codegen, the parser achieves a throughput of 537.5 MB/s, outperforming Rust's nom by 1.9x and Haskell's parsec by 44x.
Compiling grammars to specialized DFA matchers at compile time is superior to composing combinators at runtime, but the real engineering triumph here is integrating automatic common-head factoring directly into the compiler's codegen to guarantee performance safety.
* **Compile-Time Specialization vs. Runtime Combinators**: While libraries like Rust's `nom` and Haskell's `parsec` evaluate combinators at runtime, Koru's `std/parser` lowers the grammar directly to specialized recursive-descent rules at compile time, yielding significant performance gains.
* **Eliminating PEG Performance Cliffs**: Backtracking on identical prefix elements (e.g., in `item "," rest | item` PEG lists) can cause nested right-hand structures to explode exponentially (depth 24 requiring $2^{24}$ parses). Common-head factoring solves this by running the head once and keeping the result.
* **Performance Gate Safeguards**: To prevent silent performance regressions from returning, the Koru test suite now contains a "cliff gate" testing left- and right-nested variants to ensure they maintain a fixed performance ratio.
* **Benchmarking Context**: Koru leads general-purpose parser libraries at 537.5 MB/s but still leaves room for improvement compared to hand-rolled Zig validators (853.5 MB/s).
DISCOVERED
1h ago
2026-07-18
PUBLISHED
1h ago
2026-07-18
RELEVANCE
AUTHOR
korulang