Skip to content

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

Closed

Description

@JuroOravec

What happens

Since the fix for #272 (PR #470), a template can nest at most 256 levels of Citry logic, inside a limit of 512 nested tags. Citry logic means every c- tag except <c-raw>, plus each c-if=, c-elif=, c-else, c-for= or c-empty attribute. A deeper template raises SyntaxError with the code citry.parse.too-deep.

Most of the Python code that walks a template now keeps its own list of what to visit, instead of calling itself once per level. #355, #356, #360, #364, #377 and #397 rewrote it. So a template at the limit renders in about the same number of Python frames as a shallow one. The frame-budget test from #403 (packages/py/citry/tests/_frame_budget.py) starts each render 200 frames deep, to stand in for the application, and lets Citry use at most 500 more. In #403's measurements, the deepest stack at 256 levels was 145 frames (component tags and fills, with Vue), and it was the same at 128 levels, so it is a fixed cost.

Two cases still use Python frames in proportion to how deep or how long the template is. They are what remains of this issue.

1. Forwarded slots: about 8 to 10 frames per component in the chain

When a component passes its slot content on to another component's slot, and that one passes it on again, each component in the chain adds about 8 to 10 Python frames. #403 measured 36 frames for a chain of 1 and 59 for a chain of 4, and a probe for this issue measured 28, 68 and 228 frames for chains of 1, 5 and 21. A passed fill still renders through a Slot call (SlotNode._render_direct, nodes/__init__.py:2962). That call starts a new run of _render_body, the loop that renders a template body (_TemplateSlotContent._render, nodes/__init__.py:534), instead of adding the fill to the loop already running. #397 left this as it was on purpose.

The nesting limit can't prevent this, because it counts each template on its own. Measured on CPython 3.14.9 with a debug build of citry_core, the default render path and Python's default recursion limit of 1,000: a chain of 80 components renders, and a chain of 100 raises RecursionError at the innermost <c-slot />. When an application already holds 200 frames, the break should come at about 60 to 80 components (estimated from the per-component cost, not measured). The syntax docs say that a long chain can raise RecursionError.

The frame-budget test checks only the cost per component: a chain of 4 may cost at most 12 frames more per extra component than a chain of 1. No test renders a long chain.

2. simple='vue' components: about 1 frame per level

A simple='vue' component renders through Python code that Citry generates from its template (_SimpleJsonCodegen, _vue/leaf_program.py:1459; the depth cap is described at :1438-1448). That code calls itself once per level. Measured on the same setup, second renders used 22, 142 and 270 frames at 8, 128 and 256 levels. A Vue component without simple='vue' uses that generated code only for templates under 16 levels (leaf_program.py:2816-2820); deeper ones use _evaluate_inner, which loops instead of calling itself. A simple='vue' component has nothing to fall back to.

At the limit this fits within Python's default recursion limit. But the frame-budget test has no deep simple='vue' fixture, so nothing checks it under the lowered limit.

Who hits it

  • An app that passes slot content through a long chain of components: about 60 to 100, depending on how many frames the application already uses.
  • A deeply nested simple='vue' component in an app that already uses many frames. Nobody is known to hit this at 256 levels.

Fix direction

  1. Add a simple='vue' fixture at the logic limit to _frame_budget.py, so this case is covered under the same budget as the others.
  2. Render a forwarded fill in the _render_body loop that is already running, the way <c-if>, <c-for> and slot fallbacks do since perf: render nested control flow without one Python call per level #356 and perf: render nested slot fallbacks without a Python call per level #397. If that turns out to be too invasive, count the chain length and raise a clear error that names the chain instead of RecursionError. Either way, add a test that renders a long chain under the budget.
  3. Give simple='vue' an evaluator that does not call itself per level, or one generated without nesting. Capping the depth, as _enter_generated_body does at 16 levels for the generated HTML code, works only when slower code can take over past the cap, and simple='vue' has none today.

Each change touches code that runs on every render, so each needs a render benchmark beside it, and it lands only if ordinary templates do not get slower.

Raising the logic limit

Once 2 and 3 land, the logic limit could rise to 512, or the separate logic count could go. These numbers have not been measured at 512 logic levels:

  • The simple='vue' evaluator would need about 526 frames, more than the test's budget of 500. This is extrapolated from 1 frame per level, so 3 has to land first.
  • The Vue server renderer's caps in crates/citry_vue_compiler/src/server_render.rs look large enough: MAX_READ_DEPTH (line 461), MAX_DEPTH (line 2425) and MAX_MANIFEST_DEPTH (line 2216) are all 2,048. At 512 logic levels they would reach about 1,024, 1,536 and 1,030, estimated from their doc comments. Each needs a test at 512 logic levels.
  • citry check takes time that grows with roughly the cube of the nesting depth (citry check slows down with roughly the cube of template nesting depth #384). This already limits the budget test to two citry check fixtures at 256, and it gets worse at 512.

The diagnostic message, the frame-budget tests, the parser's deep test and the smoke script read the limit from the parser. These still state 256 or 512 and would change with it:

  • crates/citry_template_parser/src/nesting.rs (the constant, and its comment that the logic limit stays below the tag limit) and tests/nesting_limits.rs;
  • crates/citry_core_py/src/template_parser.rs and the parse.py and compile.py docstrings in citry_core;
  • the citry.parse.too-deep entry in packages/protocol/diagnostics/v1/catalog.json;
  • the comments in crates/citry_vue_compiler/src/server_render.rs, stack.rs and tests/deep_nesting.rs;
  • the syntax docs, docs/design/template_grammar.md, the parser's docs/agent/INDEX.md, and the changelogs.

Activity

  1. changed the title [-]Follow-up to #272: walk template bodies in Python without recursion, so the 128-level logic-tag limit can rise[/-] [+]Follow-up to #272: forwarded slot chains and simple='vue' components still use Python frames per level[/+] on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions