release 0.2.3: interpreter phase-1 port (1.38x speedup)#14
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughVersion 0.2.3 release introducing interpreter optimizations and parity testing infrastructure. Extracts shared grammar analysis utilities for whitespace first-character derivation and expression shape inspection. Optimizes the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
Ports the six phase-1 optimizations from the 0.2.2 generator rework to the interpreter (
PegEngine). Measured 1.38× speedup on the 1,900-LOCFactoryClassGenerator.java.txtfixture (pre-port: 355 ± 7 ms/op → post-port: 258 ± 6 ms/op, JMH avgT, JDK 25).1.38× is below the ≥1.5× plan target. Documented honestly in CHANGELOG: the interpreter's per-invocation expression-switch dispatch dominates per-call cost; phase-1's allocation-elision wins translate less dramatically than they do for the generator's rule-specialized output. Phase-2 optimizations (
choiceDispatch,markResetChildren,inlineLocations,selectivePackrat) remain generator-only and are documented as structurally non-portable to the interpreter.What changed
org.pragmatica.peg.grammar.analysishostsFirstCharAnalysisandExpressionShape. BothParserGeneratorandPegEngineconsume it — single source of truth for first-char derivation from a%whitespacerule.PegEngineapplies all six phase-1 optimizations unconditionally (no configuration surface). Rationale per plan §0.2.3: interpreter is a single runtime class, no code-size trade-off to gate.§6.5error-message unification to bracketed label ("[...]"/"[^...]") now applies to the interpreter too; no existing tests asserted on the old"character class"string, so zero test fallout.GeneratorFlagInertnessTestremains 3/3 green — generator emission is byte-identical.Tests
RoundTripTest, addressed in 0.2.4).Phase1InterpreterParityTest(22/22) with a dedicated interpreter baseline atsrc/test/resources/perf-corpus-interpreter-baseline/.interpretervariant added toJava25ParseBenchmark; raw results atdocs/bench-results/java25-parse-interpreter.json.Test plan
mvn test— 587/587 + 1 skippedmvn install—peglib-0.2.3.jarpublished locallyPhase1InterpreterParityTestGeneratorFlagInertnessTest3/3)Summary by CodeRabbit
Release Notes v0.2.3
New Features
Documentation
Tests
Chores