Skip to content

perf: hash site ids from the parent's state and look up finding positions by line start - #538

Merged
JuroOravec merged 2 commits into
mainfrom
perf/vue-compile-depth
Oct 28, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
perf/vue-compile-depth

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Part of #501.

citry check took longer than linear time on deeply nested templates. This PR fixes the two causes that can be fixed without changing the compiler's output. The rest needs a change to the Vue compiler's output format and is filed as two issues labeled v1.1 (#537 and #536).

What changes

  • Site ids. The Vue compiler's walk that records each element's metadata hashed every element's whole path from the template root again, so its cost grew with size times depth. Each element now extends its parent's SHA-256 state with its own segment. The site ids are byte-for-byte the same; a new Rust test checks each one against the hash of the joined path and one fixed value, and I compared all site ids on the 512-level div and 256-level c-elif templates.
  • Finding positions. _byte_offset_coordinates in the checker re-encoded and rescanned the source up to each finding's offset, so the cost grew with findings times source length. A new byte_offset_position in _source_lines.py finds a source's line starts once (it keeps them for the last 8 sources) and looks each offset up with a binary search. Compared with the old code on 273,000 random offsets over CR, LF, CR LF, form feed, U+2028, é and emoji, including offsets past the end and inside a character, every one gave the same result or the same UnicodeDecodeError. A negative offset, which no caller passes, now counts as 0; the old code returned a line of -1 or a wrong position.

Measurements

Release builds, CPython 3.15.1, macOS arm64, base f67bb05a5 (main with #527). The templates are #501's: <div> nested depth times, and <c-if cond="not flag">no</c-if><c-elif cond="flag"> repeated depth times with matching </c-elif><c-else>else</c-else>. A small script defines one component with that template and times check_project on it.

citry check (check_project on one component), median of 3 runs:

Template Depth main This PR
c-if/c-elif/c-else 64 0.059 s 0.056 s
128 0.096 s 0.081 s
256 0.204 s 0.161 s
<div> 128 0.039 s 0.040 s
256 0.052 s 0.054 s
512 0.087 s 0.093 s

The div template reports no findings, so only the site-id change applies there. Its end-to-end times are 1 to 7 percent slower, within the spread of 3 runs on a busy machine; the Rust compile below is faster.

The Vue compile alone (Rust, compile plus JSON serialization, ms per compile):

Template Depth main This PR
<div> 128 1.21 1.05
256 3.87 3.18
512 14.09 11.29
c-elif 64 2.84 2.63
128 8.71 7.55
256 30.64 24.87

What is left

The compile still grows about 3 times per doubling. Two causes remain: one in the output of Citry's wrapper and one in the code vize emits. Neither is in a part of vize that Citry patched.

A release build of the whole check already grows about 2 times per doubling on these templates, so the remaining compile cost can wait; both issues are labeled v1.1.

Out of scope: a few other places turn a byte offset into a line the same per-call way (_vue_loop_errors.py _line, _component_graph.py, ext/events/bindings.py, _vue/capture.py, _vue/direct_capture.py, and citry_lsp/type_analysis.py). None of them showed in the profiles of the #501 templates, and I did not measure how often each runs, so they are left for a separate sweep if a profile shows one.

Checks

  • cargo test --release -p citry_vue_compiler, cargo clippy and rustfmt on the crate.
  • pytest: the check, lint and Vue tests (test_check*.py, test_*lint*.py, test_vue_prepared.py, test_vue_compile_lint.py, the render-body and slot-forwarding snapshot tests) and citry_lsp, 2,480 passed.
  • ruff, and mypy on macOS and with --platform linux, on the changed files.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits October 28, 2026 23:25
The Vue compiler's walk that records each element's metadata hashed every
element's whole joined path again, so a deep template spent time in
proportion to its size times its depth. Each element now copies its
parent's SHA-256 state and adds only its own segment. The site ids are
unchanged; a new test checks them against the hash of the joined path and
one fixed value.

Part of #501.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each finding's line and column re-encoded and rescanned the source up to
its offset, so `citry check` spent time in proportion to the number of
findings times the source length. The checker now finds a source's line
starts once, keeps them for the last 8 sources, and looks each offset up
with a binary search. Positions are unchanged for every offset inside
the source; a negative offset now counts as 0.

Part of #501.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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