Skip to content

Bound resource use when iterating ranges - #2117

Open
ianks wants to merge 2 commits into
mainfrom
ianks/lazy-range-iteration
Open

ianks wants to merge 2 commits into
mainfrom
ianks/lazy-range-iteration

Conversation

@ianks

@ianks ianks commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Depends on #2118 for the existing CI repairs. This PR contains only the range implementation, regression tests, and documentation.

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 against the repaired baseline. 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
Assisted-By: devx/b8d3b9bd-01a3-41b1-90f8-632318b798e4
Assisted-By: devx/b8d3b9bd-01a3-41b1-90f8-632318b798e4
@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
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.

1 participant