Reduce memory allocations for RI and POT generators - #1788
Open
skatkov wants to merge 3 commits into
Open
Conversation
skatkov
requested a deployment
to
fork-preview-protection
August 26, 2026 12:09 — with
GitHub Actions
Waiting
skatkov
force-pushed
the
optional-store-method-source
branch
from
August 26, 2026 12:21
55caf23 to
e89f08c
Compare
skatkov
requested a deployment
to
fork-preview-protection
August 26, 2026 12:21 — with
GitHub Actions
Waiting
RDoc currently syntax-highlights and retains every Ruby method body during parsing, regardless of whether the selected generator renders method source. This PR adds a generator capability for controlling method-source collection. RI and POT opt out, while Darkfish, Aliki, and unknown third-party generators retain the existing behavior. This reduces roughly 50% of allocations for generators that opt-out.
skatkov
force-pushed
the
optional-store-method-source
branch
from
August 26, 2026 12:28
e89f08c to
afe4edb
Compare
skatkov
requested a deployment
to
fork-preview-protection
August 26, 2026 12:28 — with
GitHub Actions
Waiting
skatkov
requested a deployment
to
fork-preview-protection
August 26, 2026 17:25 — with
GitHub Actions
Waiting
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.
Each documented method currently retains an array of
RDoc::Parser::RubyColorizer::ColoredTokenobjects and their fragmented source strings.This data is unnecessary for:
Large generated SDKs can contain millions of tokens. Avoiding those allocations substantially reduces parsing time and memory without changing generated output.
Implementation
Generators can declare whether they require method source:
The Ruby parser checks that capability before syntax highlighting a method body.
Generators without the capability default to true, preserving compatibility with existing third-party generators.
This also allows third-party generators (like rdoc-markdown) to skip this costly process if they don't have need for
method.token_streamormethod.markup_code.If
store_method_source?was disabled, buttoken_streamwas still accessed, an error will be raised.Benchmark
Here is a code that was used for benchmark this fix:
https://github.com/skatkov/rdoc-store-method-source-benchmark
RDoc 8.0.0 and
google-api-client0.53.0 on Ruby 4.0.6: