Improve pure-Ruby parser caching and literal alternatives#22
Open
suleman-uzair wants to merge 20 commits into
Open
Improve pure-Ruby parser caching and literal alternatives#22suleman-uzair wants to merge 20 commits into
suleman-uzair wants to merge 20 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refines memoization behavior by introducing a separate adaptive cache threshold fallback for parser-class parsing contexts (defaulting to immediate caching), while keeping the existing atom-level default threshold. It also adds an optimization to Alternative to reduce work for large ordered choices via literal-prefix indexing, plus accompanying specs and a benchmark case to compare cache-threshold behaviors.
Changes:
- Add a
:parser_defaultadaptive cache threshold for unnamed/unnamed-override parser classes (set to0), while keeping the atom-level default at1000. - Adjust cache keying to better separate strict (consume-all) vs prefix behavior while ensuring successful prefix parses are cached consistently.
- Add literal-prefix indexing for large
Alternativechoices, plus focused specs and a benchmark input/parser to compare cache-threshold approaches.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/parsanol/source_spec.rb | Adds coverage for Source#remaining. |
| spec/parsanol/atoms/context_spec.rb | Adds specs for atom vs parser-class cache thresholds and consume-all boundary behavior. |
| spec/parsanol/atoms/alternative_spec.rb | Adds specs validating literal-prefix indexing behavior and error-detail preservation. |
| spec/parsanol/atom_results_spec.rb | Adds coverage for cached prefix successes across strict named subexpressions. |
| lib/parsanol/source.rb | Adds Source#remaining for non-advancing access to the unconsumed input. |
| lib/parsanol/atoms/context.rb | Introduces :parser_default threshold and refines memoization keying/lookup behavior. |
| lib/parsanol/atoms/alternative.rb | Adds large-choice literal indexing and lazy choice-error generation. |
| benchmark/run_all.rb | Adds cache-threshold comparison parsers and input-type selection plumbing. |
| benchmark/README.md | Documents the new cache-threshold benchmark input type and CLI flag. |
| benchmark/parsers/cache_threshold_parsanol.rb | Adds a synthetic recursive grammar to compare cache-threshold defaults. |
| benchmark/inputs/tiny/cache_threshold.txt | Adds tiny cache-threshold benchmark input. |
| benchmark/inputs/small/cache_threshold.txt | Adds small cache-threshold benchmark input. |
| benchmark/inputs/medium/cache_threshold.txt | Adds medium cache-threshold benchmark input. |
| benchmark/inputs/large/cache_threshold.txt | Adds large cache-threshold benchmark input. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
added 5 commits
June 3, 2026 19:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR:
consume_allmode and preserves the Parslet-compatible prefix-success reuse for ordered choicedynamic {}blocks or write captures, so cache thresholds stay performance-onlyAlternativechoices while preserving ordered-choice semantics and complete failure reportingalternativesso the lazily built index cannot go staleSlice#hash,Buffer#clear!, andSource::LineCachebenchmark/benchmark_suite.rband removes the legacy ffi-hash/ffi-json benchmark plumbing superseded by the unified parsanol-rsparse()APIHISTORY.txtto match the current backends and the behavior changes aboveThis affects the pure-Ruby parser path only. Native parsing continues through the Rust-backed parser path.