Repository navigation
test: allow one frame per level for deep simple='vue' templates and document the cost - #545
Merged
Merged
Conversation
…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]>
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.
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 perc-iforc-forlevel. 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: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.py, run bytest_frame_budget_python.pyandtest_frame_budget_rust.py): a newsimple_vue_templatefixture 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.test_render_depth_frames.py):test_simple_vue_templates_use_one_python_frame_per_levelchecks 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.Checks
test_render_depth_frames.py: 72 passed.test_frame_budget_rust.pyandtest_frame_budget_python.pywithCITRY_FRAME_BUDGET_ANY_OS=1: both passed (macOS, CPython 3.15).python -m docs_site build-checkwas not run locally, because the docs extra has no CPython 3.15 wheel forminify-html. CI runs it. The links and the heading length were checked by hand.🤖 Generated with Claude Code