Avoid foreign grammar calls in Markdown parser - #1818
Open
skatkov wants to merge 2 commits into
Open
Conversation
Inline the literal rules in the main grammar to avoid resetting scanner state for every match.
Documentation previewCommit: |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The rules are inlined without semantic changes, and all references and supporting configuration are updated consistently.
Pull request overview
Inlines Markdown literal rules to eliminate foreign-parser state resets and improve parsing performance.
Changes:
- Moves common literal rules into the primary Markdown grammar.
- Removes the obsolete literals grammar and generated parser.
- Updates generation, linting, and contributor documentation.
File summaries
| File | Description |
|---|---|
Rakefile |
Removes the deleted grammar from parser generation. |
lib/rdoc/markdown/literals.rb |
Deletes the generated foreign parser. |
lib/rdoc/markdown/literals.kpeg |
Deletes the foreign grammar source. |
lib/rdoc/markdown.rb |
Uses locally generated literal rules. |
lib/rdoc/markdown.kpeg |
Defines literal rules directly. |
CONTRIBUTING.md |
Updates parser documentation. |
AGENTS.md |
Updates generated-file documentation. |
.rubocop.yml |
Removes the deleted generated file exclusion. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
The Markdown parser delegates common character rules to a foreign kpeg grammar. Each match resets the foreign parser's input and scanner state, making these frequently invoked rules a significant allocation and CPU hotspot.
This inlines the literal rules in the main grammar to avoid resetting scanner state for every match. Because all these values are inlined, we can also loose literals.kpeg file (and all the mapping associated with it).
On a full Rails documentation build, median runtime decreased from 17.92s to 14.94s (16.6%), peak RSS decreased by 10.4%, and allocations decreased by 24.4%.
Command:
bundle exec rdoc --format=markdown --quiet --force-output \ '--exclude=(?:^|/)(?:app/assets|lib/templates)/|\.(?:json|rbs|xml|xsd)\z' .