Add cumulative resource score tracking across partial renders#2058
Merged
Add cumulative resource score tracking across partial renders#2058
Conversation
Add cumulative_render_score and cumulative_assign_score counters to ResourceLimits that accumulate across reset() calls, with optional cumulative_render_score_limit and cumulative_assign_score_limit to cap total work across all partial renders. Also add a reached? check in BlockBody's render loop so that once a cumulative limit triggers, the parent template stops processing further nodes. Bump version to 5.12.0.
Maaarcocr
reviewed
Mar 18, 2026
lib/liquid/block_body.rb
Outdated
| break if context.interrupt? # might have happened in a for-block | ||
| end | ||
| idx += 1 | ||
| break if context.resource_limits.reached? |
Contributor
Author
There was a problem hiding this comment.
makes it so we immediately stop rendering instead of letting each subsequent partial reset the flag and blow the limit again in a loop
Contributor
Author
There was a problem hiding this comment.
might be better to address this in ResourceLimits#reset
Instead of checking reached? in BlockBody's render loop, enforce cumulative limits in reset() itself. Since reset() is called before the begin/rescue MemoryError block in Template#render, the raise propagates to the parent naturally — no changes to BlockBody needed.
Maaarcocr
approved these changes
Mar 18, 2026
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.
Situation
Template#renderunconditionally callsresource_limits.resetbefore rendering, which zerosrender_scoreandassign_score. Since both{% render %}and{% include %}go throughTemplate#renderfor each partial, the per-template scores reset on every partial invocation — makingrender_score_limitandassign_score_limitineffective at bounding total work across partial renders. A template split across many small partials can execute unbounded cumulative work while each individual partial stays under the limit.Execution
Added
cumulative_render_scoreandcumulative_assign_scorecounters toResourceLimitsthat piggyback on the existingincrement_render_score/increment_assign_scoremethods but survivereset()calls. Two new optional limits (cumulative_render_score_limit,cumulative_assign_score_limit) are checked alongside the existing per-template limits. When unset (nil), the cumulative checks are skipped entirely — zero behavior change for existing users.Backwards compatibility
The existing
render_score,assign_score,render_score_limit,assign_score_limit, andreset()behavior are completely unchanged — per-template scores still reset on everyTemplate#rendercall exactly as before. The new cumulative fields default tonil(limits) and0(counters), so applications that never setcumulative_*_limitwill never trigger the new code paths.