Reduce allocations from parsing include params #8851
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.
Problem
Tags::IncludeTag#parse_params
is called from within the:render
method. to generate the Hash object forcontext["include"]
from string markup by using a regex. Consequently, if an include is rendered numerous times, a lot of intermediate objects get allocated.Prior art
The allocations were partially reduced for
v4.2.0
in #8192.Current Proposal
:initialize
method. The final Hash is however generated only via:render
calls.IncludeTag::ParameterTokenList
class to avoid generating new Hashes if the params arecontext
-agnostic (i.e. no variable).Additional Notes
Also includes a benchmark script that compares current proposal with
v4.2
optimization and pre-v4.2
implementation.