You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The editor's per-expression template search grows with the square of nesting depth #497
The language server finds the Python names around each expression in a template with template_python_queries (packages/py/citry/citry/_template_python.py:254). It collects the start of every Python value in the template, then searches from the root once for each one (_query_in_template, :1923), going down only into the bodies that contain that position (_query_in_node and _node_body_contains, :2030, :2240). Each search also builds the chain of control tags around the position.
So one search reads about as many nodes as the template is deep, and a template with an expression at every level makes the editor read about depth² nodes for each change. The editor calls this on every document update (packages/py/citry_lsp/citry_lsp/engine.py:1088, :5591). citry check does not use it.
#384 makes each read of the parsed tree copy one node instead of a whole subtree, so this search gets much cheaper, but it still grows with the square of the depth. Ordinary templates are a few dozen levels deep at most, so this matters mainly for deep or generated templates near the nesting limits (256 Citry logic levels, 512 tags).
Otherwise, collect every query in one walk: keep the stack of enclosing control tags while walking down, and emit a query for each Python value as the walk reaches it. That costs time proportional to the number of nodes, and it replaces one search per position with one walk per template.
The result must stay the same: the same queries, in the same order, with the same lexical context. The existing _template_python tests cover that.
Activity
perf(lsp): find every template expression's Python names in one walk (#…
docs: correct #497's changelog figures and walk comments (#541)