Skip to content

Bound resource use when iterating ranges - #2117

Merged
ianks merged 1 commit into
mainfrom
ianks/lazy-range-iteration
Sep 17, 2026
Merged

ianks merged 1 commit into
mainfrom
ianks/lazy-range-iteration

Conversation

@ianks

@ianks ianks commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

The CI repairs landed in #2118. Declarative range behavior and resource-limit coverage landed in Shopify/liquid-spec#165; this PR pins its merged revision and retains Ruby-only allocation, counter, repeated-render, and custom-Range checks.

for and tablerow can materialize an entire range before resource limits run. This replaces that allocation with a small integer-range window: length, offsets, and reversal use arithmetic, and values are generated as the loop visits them.

Each visited range item consumes render score before entering the body, including empty bodies. Early break only pays for the values visited; loop metadata and offset:continue retain the full selected length. tablerow also checks its generated HTML incrementally, including captured output and break paths.

Tight render-score budgets may now stop range loops earlier. Output-length limits still bound bytes, not CPU work in output-free loops. Non-range collections keep the existing slicing and load_slice behavior.

Validation and cost

All lax/strict/strict2 tests, four liquid-spec adapters, RuboCop, and the memory-profile task pass locally. Each adapter passes 2,845 liquid-spec cases, including the 10 staged range resource-limit cases and 9 imported compatibility cases. Regression tests guard both historical materialization paths, so they fail safely against the old code rather than attempting huge allocations.

Five paired Ruby 4.0.6 benchmark runs measured about 2% overhead for small for range loops and 6% for tablerow range loops with the additional checks. The range window stayed at 80 bytes for cardinalities of 10, one million, and one billion; output storage is separate.

@ianks
ianks requested a review from karreiro September 15, 2026 17:42
@ianks
ianks changed the base branch from main to ianks/liquid-ci-baseline September 15, 2026 19:56
@ianks
ianks force-pushed the ianks/lazy-range-iteration branch from 282db86 to cdba4e9 Compare September 16, 2026 02:43
@ianks
ianks changed the base branch from ianks/liquid-ci-baseline to main September 16, 2026 02:43
@ianks
ianks requested a review from Maaarcocr September 16, 2026 20:51
Assisted-By: devx/b8d3b9bd-01a3-41b1-90f8-632318b798e4
@ianks
ianks force-pushed the ianks/lazy-range-iteration branch from ac8a7d3 to 47a93bc Compare September 16, 2026 23:14
@ianks
ianks merged commit 4e5198b into main Sep 17, 2026
14 checks passed
@ianks ianks mentioned this pull request Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants