Repository navigation
test: confirm templates at the logic limit fit a fixed Python frame budget - #403
Merged
Merged
Conversation
JuroOravec
force-pushed
the
test/frame-budget
branch
from
October 25, 2026 14:07
d4ff60a to
dc0d596
Compare
…udget Test 5 of #272. Each fixture is nested to 256 logic levels and runs 200 frames deep with only 500 frames of room above it: control-flow tags and their shorthand attributes, component tags, slots and their fallbacks, fills, simple components, a fill shown by an expression, components in loops, a call run, a template in an attribute, pure and cached components, 512 plain elements, and a slot passed on through one and four components. Each runs without Vue, with Vue, and with the i18n extension, and its output under the low limit must equal its output under the normal one; its innermost level must render, and the cached component must replay. The deepest stack at 256 may be at most 20 frames above the one at depth 8, or at depth 128 with Vue, whose assembler has a fixed cost. The two render paths are separate test files, so CI runs them on separate workers. They are qualification tests that run only on Linux, because frame counts depend on the Python version, not the OS. The language server gets a similar check on three templates. The root changelog gets one entry for the whole series, citry_lsp gets one for its analysis, and the extension docs say to walk ctx.nodes with a loop. The citry._walk docstring now shows Call with the function first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
test/frame-budget
branch
from
October 25, 2026 14:28
dc0d596 to
ada2047
Compare
This was referenced Oct 27, 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.
What this adds
This is the fifth check planned in #272. It checks that a template nested to 256 levels of Citry
logic tags still renders when the application around Citry already holds
part of Python's stack. That is the depth the planned nesting limit in
#272 will allow. A web framework, middleware, a view and a test runner sit
on the stack before Citry starts, so each fixture starts with 200 frames already on the stack,
with Python's recursion limit lowered to allow only 500 more frames.
Under that limit each fixture renders twice and serializes, and two of
them also run
citry check. The fixtures cover:c-if=/c-for=shorthand attributes;<c-component>,<c-element>and<c-provide>;which Citry renders with one call per row;
Each runs without Vue, with Vue, and with the i18n extension (the slot
chain only without and with Vue). The events extension is on in all of
them, as it is by default.
Several places in Citry catch
RecursionErrorand quietly do less, so arun that only finishes would prove little. For each fixture:
one;
server HTML leaves elements nested deeper than about 129 to the browser);
depth 8. With Vue, the comparison is with depth 128 instead, because
the code that builds the data Vue receives makes up to 128 frames of
nested calls before it switches to a loop. That cost is fixed and does
not grow with each level;
per extra component.
The language server gets a similar check in
packages/py/citry_lsp/tests/test_frame_budget.py, on three templatesthat each end in an unknown component, so the check also shows that the
whole template was analyzed.
Results
Everything passes on both render paths: the native Rust renderer and
the pure-Python one that PyPy and free-threaded builds use. The deepest
stacks measured at 256:
<c-for>with<c-empty>, and every shorthand, with VueThe cached component replayed from its cache on every variant, and the
call-run fixture rendered its three rows at the bottom. A slot passed on
through four components costs 59 frames at 256, and the same at depth 8
without Vue and at depth 128 with Vue, so
the cost of each component it passes through does not grow with depth.
The deepest stack, 145 frames, uses under a third of the 500-frame budget,
so the limit can ship at 256.
Cost in CI
The two render paths are separate test files
(
test_frame_budget_rust.pyandtest_frame_budget_python.py, sharing_frame_budget.py), so CI can run them on separate workers. Frame countsdepend on the Python version, not the operating system, so they, and the
language-server test, run only in the Linux jobs for Python 3.11 to 3.14
and skip on Windows and macOS (and on a local macOS run, unless
CITRY_FRAME_BUDGET_ANY_OS=1is set). They carry thequalificationmarker, so the fast local gate (
scripts/check.py --profile fast) skipsthem; the full gate and the CI test jobs run them.
citry checkruns once per checked fixture, at the limit and under thelow limit, and its findings are compared with a check at depth 128 under
the normal limit, which costs an eighth as much. Each checked template
ends in an undefined name, so the findings are the same at any depth and
show that the check reached the innermost level.
Measured on a laptop with a debug build of
citry_core, which is alsowhat CI installs. The second column was measured while other test suites
loaded the machine (load average about 30), so it runs slow; the third
estimates a quiet machine from the Rust path, whose code did not change
between a quiet and a loaded run (87 s and 155 s):
citry checkrunsWhat this adds to each of the four Linux test jobs: about 4 minutes
of serial work on a laptop, and likely 5 to 6 minutes on a GitHub runner,
whose cores are slower. The jobs run four workers with
--dist loadfile,and each of the three files goes to one worker, so the job's wall time
grows by roughly the longest file plus its share of the rest: likely 2 to
3.5 minutes per Linux job. The remaining
citry checkcost shrinksfurther once #384 makes the check fast.
Also in this PR
CHANGELOG.md: one entry for the whole series that makes deeptemplates render without
RecursionError(perf: render nested control flow without one Python call per level #356, perf: walk templates on a first render without one Python call per level #360, fix: walk render output with the same Python frames at any template depth #364, perf: walk parsed templates in check and the LSP without one Python call per level #377,perf: render nested slot fallbacks without a Python call per level #397). It replaces two lines: the caveat that templates nested past
about 300 levels raise
RecursionErroror crash (the series and fix: parse and compile deeply nested templates on any thread without crashing #343removed both), and perf: render nested slot fallbacks without a Python call per level #397's separate entry for nested
<c-slot>fallbacks, which the new entry covers.
packages/py/citry_lsp/CHANGELOG.mdgets one for the editor.docs_site/content/advanced/extensions.md: a short section tellingextension authors to walk
ctx.nodeswith a loop.citry/_walk.py: the docstring now showsCall(function, *args, **kwargs), with the function first, as it is called.Checks run
with
CITRY_FRAME_BUDGET_ANY_OS=1.ruffon the changed files.the docs extra); the docs-check CI job covers the new section.
section, each with a prose pass. Their findings are folded in.
Part of #272.
🤖 Generated with Claude Code