Skip to content

test: confirm templates at the logic limit fit a fixed Python frame budget - #403

Merged
JuroOravec merged 1 commit into
mainfrom
test/frame-budget
Oct 25, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
test/frame-budget

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

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:

  • control-flow tags, and their c-if=/c-for= shorthand attributes;
  • component tags, <c-component>, <c-element> and <c-provide>;
  • slots with fallbacks, and fills;
  • simple components;
  • a fill shown through an expression;
  • components in loops, and a loop whose body is one keyed component,
    which Citry renders with one call per row;
  • a template inside an attribute;
  • pure and cached components;
  • 512 plain elements;
  • a slot passed on through one and through four components.

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 RecursionError and quietly do less, so a
run that only finishes would prove little. For each fixture:

  • its output under the low limit must equal its output under the normal
    one;
  • its innermost level must render (checked without Vue: with Vue, the
    server HTML leaves elements nested deeper than about 129 to the browser);
  • the cached component must replay from its cache;
  • the deepest stack at 256 may be at most 20 frames above the deepest at
    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;
  • passing a slot on through four components may cost at most 12 frames
    per extra component.

The language server gets a similar check in
packages/py/citry_lsp/tests/test_frame_budget.py, on three templates
that 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:

Fixture Frames
Most fixtures, without and with Vue, and with i18n 36
<c-for> with <c-empty>, and every shorthand, with Vue 48
Component tags, fills, and fills shown by an expression, with Vue (the same at depth 128: a fixed cost) 144 to 145
A slot passed on through one component / through four 36 / 59

The 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.py and test_frame_budget_python.py, sharing
_frame_budget.py), so CI can run them on separate workers. Frame counts
depend 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=1 is set). They carry the qualification
marker, so the fast local gate (scripts/check.py --profile fast) skips
them; the full gate and the CI test jobs run them.

citry check runs once per checked fixture, at the limit and under the
low 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 also
what 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):

Test Loaded machine Quiet machine (estimate)
Rust render path 155 s 87 s (measured)
Python render path, with the two citry check runs 206 s about 115 s
Language server 40 s about 25 s
Serial total 401 s about 3.8 minutes

What 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 check cost shrinks
further once #384 makes the check fast.

Also in this PR

Checks run

  • Both render-path test files and the language-server test, run locally
    with CITRY_FRAME_BUDGET_ANY_OS=1.
  • ruff on the changed files.
  • The docs-site build checks were not run locally (this environment lacks
    the docs extra); the docs-check CI job covers the new section.
  • An independent code review and a first-time-reader review of the docs
    section, each with a prose pass. Their findings are folded in.

Part of #272.

🤖 Generated with Claude Code

…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
JuroOravec merged commit 7084ce8 into main Oct 25, 2026
24 of 28 checks passed
@JuroOravec
JuroOravec deleted the test/frame-budget branch October 25, 2026 14:32
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