Repository navigation
perf: walk parsed templates in check and the LSP without one Python call per level - #377
Merged
Merged
Conversation
…r level `_markup_lint`'s `_walk` and the nine `_collect_*` template walkers in `_browser_expressions` (browser expressions, bindings, declarative events, component prop sites, mark literals, i18n directives, state bindings, state target errors and enclosing elements) called themselves once per nested element or template attribute. They run in `citry check`, the LSP and on some first renders. Each is now a walk generator run by `citry._walk.run`, with the same results in the same order. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The registry lint's template walkers (repeated calls, Vue attributes, server event calls and forms, the disabled-form walk, template URLs) and the CSS lint's `walk` called themselves once per nested element or template attribute. They are now walk generators run by `citry._walk.run`. `template_has_vue_attributes` keeps its signature for `_checker`, which calls it. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ll per level `analysis`'s `_collect_alpine_attributes`, `_collect_attribute_values` and `_collect_misspelled_directives` called themselves once per nested element or template attribute. They are now walk generators run by `citry._walk.run`. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`_markup_lint`'s `_v_pre_ranges` and `_single_root_starts` called themselves once per nested element or c-if chain. They are now walk generators run by `citry._walk.run`. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`_provide_keys`' `_walk` and `_walk_attributes` called each other once per nested element or template attribute. They are now walk generators run by `citry._walk.run`. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…evel `_checker`'s `_trans_nodes` and `_unknown_component_findings`, `_portable_ide._collect_template_tags`, `_template_python`'s `_collect_static_input_queries`, `_query_in_template` and `_query_in_node`, `_component_graph._walk_template` and the LSP engine's own `_trans_nodes` called themselves once per nested element or template attribute. They are now walk generators run by `citry._walk.run`. `citry check` on a template of 128 nested elements now peaks at the same Python stack as one of 8. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`static_template`'s writer (`write_nodes`, `write_node`, `write_if`, `write_for`, `write_component`, `write_slot`) and its fill collector called each other once per nested element, control-flow branch, component body or slot fallback. They are now walk generators run by `citry._walk.run`, so the written template and its data keys stay the same. `citry check` on 128 nested <c-if> tags now peaks at the same Python stack as 8. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n stack Six shapes, nested elements, <c-if>, <c-for>, c-if=, fills under control flow and a template in an attribute, each checked at depth 32 and 128. The deepest stack may grow by at most 20 frames. All six fail without the parsed-AST walker changes. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The LSP engine's i18n uses, template symbols, lexical definitions, references and bindings, binding and syntax references, first-node and HTML projection lookups, the root element type check in `root_element.py`, and `_template_python._query_start_indexes` called themselves once per nested element or body. They are now walk generators run by `citry._walk.run`. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Statements that discard a walk result use a bare `yield Call(...)`. `template_has_vue_attributes` keeps its full docstring, and its comment says what `run` does. The check frame test asserts that the deep template's unknown variable is found, so it cannot pass on a template the walkers never reached. Part of #272. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 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.
Part of #272. This is PR E4 from the plan for #272: the code that walks a template's parsed tree in
citry check, the LSP andcitry.analysis(the API that reports what a template uses) no longer calls itself once per level of nesting. Socitry checkon a deeply nested template needs about the same Python stack at any depth.A test that caps the Python stack at 256 levels of nesting (test 5 in the plan), the changelog entry for all of PR E, and the extension-authoring docs note come in a small follow-up PR, right after #364 merges.
What was wrong
citry checkand the LSP run many walkers over a template's parsed tree. Among them:_vue/static_template.py.Each called itself once per nested element, branch, component body or template attribute.
citry checkon a template of 128 nested<div>tags peaked at 137 Python stack frames, and on 128 nested<c-if>tags at 395. A template 400<c-if>tags deep raisedRecursionError.What changes
Each walker is now a generator.
citry._walk.run(added in #355) keeps the running walkers on a list and steps through them in one loop, so it needs no Python call per level. Where a walker called itself, it yieldsCall(walker, child, ...)and gets the child's result back from theyield. A function called from another module keeps its signature: for example,template_has_vue_attributesruns its own walk withrun, because_checkercalls it. The converted walkers:_markup_lint.py:_walk,_v_pre_rangesand_single_root_starts._browser_expressions.py: the nine_collect_*template walkers._registry_lint.py: the six template walkers, including the walk that tracks disabled forms and fieldsets._css_lint.py:walk.analysis.py: the Alpine, attribute-value and misspelled-directive collectors._provide_keys.py:_walkand_walk_attributes._checker.py:_trans_nodesand_unknown_component_findings._portable_ide.py:_collect_template_tags._template_python.py:_collect_static_input_queries,_query_in_template,_query_in_nodeand_query_start_indexes._component_graph.py:_walk_template._trans_nodes,_trans_i18n_uses,_template_symbols, the lexical definition, reference and binding lookups,_citry_binding_reference_at,_syntax_reference_at,_first_node_namedand_html_projection_slice.root_element.py: the functions that work out what type$elhas at the template's root._vue/static_template.py: the writer methods and the fill collector.Evidence
citry checkon 128 nested<div>or<c-if>tags now peaks at 28 frames, the same as at depth 8.test_check_depth_frames.pychecks six shapes (nested elements,<c-if>,<c-for>,c-if=, fills under control flow, a template in an attribute) at depths 32 and 128. It allows at most 20 frames of growth, and it asserts the deep template's unknown variable is found, which shows the walkers reached the bottom. All six fail without these changes.All 10,049 citry and citry_lsp tests pass with no expected output changed. mypy (also
--platform linux) and ruff are clean.An independent review compared the old and new code by probing both:
citry checkfindings were byte-identical across 20 shapes, and across 13 templates producing 11 finding codes;checkstayed flat at depth 300 for every shape tried, including i18n, events, Vue, svg,c-raw, URLs, Alpine and repeated calls;<c-if>tags, which raisedRecursionErrorbefore, now check.Every caller of a converted function now goes through
Callorrun. None of the converted functions usedyieldbefore, so turning them into generators changed nothing else about them.Timing:
citry checkon a 300-row template took a median of 3.90 s against 3.79 s before (+2.9%, 3 runs each), under the plan's 5% threshold forcheck.Known limits
template_python_queriestakes 21 s at depth 128 (32 s before). That time comes from the amount of work the queries do, not from stack depth, and is outside this PR.check, and their stack use stayed flat, but no test checks that yet. The follow-up's test 5 covers them.🤖 Generated with Claude Code