Skip to content

test: allow one frame per level for deep simple='vue' templates and document the cost - #545

Merged
JuroOravec merged 2 commits into
mainfrom
fix/299-simple-vue-frame-allowance
Nov 1, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
fix/299-simple-vue-frame-allowance

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Closes #299

Why the generator approach was dropped

#522 already renders forwarded slot chains in a fixed amount of Python's stack. The second part of #299 was simple='vue' templates, whose generated Python code uses one frame per c-if or c-for level. An earlier attempt (commit d1a52ac30, never pushed) ran each body below the first 15 levels as a generator, so deeper levels stopped adding frames. Its speed check failed the limit of about 1.5 times set for #299:

  • evaluation was unchanged up to 15 levels, then 2.9 times slower at 32 levels, 1.9 times at 128 and 1.6 times at 256;
  • rendering was 1.3 to 1.5 times slower.

The cost is about 4.7 microseconds per level per call, from creating a generator, a call record and a step of the loop each time a body runs. The maintainer chose to drop it. A simple='vue' template keeps one frame per level, which is about 270 frames at the 256-level logic limit, well under Python's default recursion limit of 1,000.

What this PR does

  • Frame budget (_frame_budget.py, run by test_frame_budget_python.py and test_frame_budget_rust.py): a new simple_vue_template fixture nests alternating <c-if> and <c-for> tags to the limit. It may grow by one frame for each level between the depth it is compared with and the limit (SIMPLE_VUE_FRAMES_PER_LEVEL), on top of the usual 20. The i18n variant renders the component the ordinary way, so it gets no allowance. Measured on CPython 3.15, both render paths: 29 frames at depth 8 and 268 at 256, and 140 at depth 128 and 268 at 256 with Vue. Two frames per level would fail.
  • Fast test (test_render_depth_frames.py): test_simple_vue_templates_use_one_python_frame_per_level checks the same between depth 32 and the limit for four shapes on both render paths. The existing depth test now also renders at 17 levels and at the limit.
  • Docs: the "Nesting limits" section of the syntax page and a new "Deeply nested templates" edge case on the simple components page state the cost.
  • No changelog entry: nothing a user can observe changes.

Checks

  • test_render_depth_frames.py: 72 passed.
  • test_frame_budget_rust.py and test_frame_budget_python.py with CITRY_FRAME_BUDGET_ANY_OS=1: both passed (macOS, CPython 3.15).
  • ruff check and format: clean.
  • python -m docs_site build-check was not run locally, because the docs extra has no CPython 3.15 wheel for minify-html. CI runs it. The links and the heading length were checked by hand.
  • An independent review, with a prose pass, and a docs cold read were folded in. They limited the allowance to the variants that need it, corrected the measured numbers in the comments, and reworded the docs so that stack levels are not confused with template levels.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits October 31, 2026 21:52
…ocument the cost

A simple='vue' component renders through Python code generated from its
template, one function per c-if branch and c-for body, each calling the
next, so each level of nesting adds one Python frame. Running the deeper
bodies as generators kept the stack flat but made these components up to
2.9 times slower to evaluate, so the frames stay.

The frame budget now renders a simple='vue' template at the logic limit
and allows it one frame for each level between the shallower depth it is
compared with (8, or 128 with Vue) and the limit. The i18n variant, which
renders the component the ordinary way, gets no allowance. A fast test
checks the same between depth 32 and the limit on both render paths, and
the depth test renders a simple='vue' component at the limit. The syntax
page's nesting limits and the simple components page say what the cost
is: about 270 frames at the limit, under Python's default of 1,000.

Closes #299

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit c0f8418 into main Nov 1, 2026
19 of 27 checks passed
@JuroOravec
JuroOravec deleted the fix/299-simple-vue-frame-allowance branch November 1, 2026 09:24
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.

Follow-up to #272: forwarded slot chains and simple='vue' components still use Python frames per level

1 participant