Repository navigation
perf: hash site ids from the parent's state and look up finding positions by line start - #538
Merged
Merged
Conversation
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]>
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 #501.
citry checktook 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 labeledv1.1(#537 and #536).What changes
divand 256-levelc-eliftemplates._byte_offset_coordinatesin the checker re-encoded and rescanned the source up to each finding's offset, so the cost grew with findings times source length. A newbyte_offset_positionin_source_lines.pyfinds 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 sameUnicodeDecodeError. 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>nesteddepthtimes, and<c-if cond="not flag">no</c-if><c-elif cond="flag">repeateddepthtimes with matching</c-elif><c-else>else</c-else>. A small script defines one component with that template and timescheck_projecton it.citry check(check_projecton one component), median of 3 runs:c-if/c-elif/c-else<div>The
divtemplate 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):
<div>c-elifWhat 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, andcitry_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 clippyandrustfmton the crate.test_check*.py,test_*lint*.py,test_vue_prepared.py,test_vue_compile_lint.py, the render-body and slot-forwarding snapshot tests) andcitry_lsp, 2,480 passed.--platform linux, on the changed files.🤖 Generated with Claude Code