perf: cut elementary allocation and algorithmic tech debt#462
Merged
Conversation
VM runtime - checkpoint: maintain max_frame_ref via a per-checkpoint prefix-max instead of an O(n) stack rescan on backtrack (was O(N^2) on any backtracking-heavy query; ~19x faster on a deep-backtrack query over a 740 KB file) - value/materializer: write JSON output directly into the buffer (escape, span ints, indentation), store NodeHandle.kind as &'static str, reserve struct field capacity — output formatting allocations drop from ~20k/48k to ~17 Compiler / core - replace linear scans with existing O(1) lookups (field/def/variant/ref resolution); FxHashMap for the interner; lex() capacity hint - InstructionIR::successors() returns a borrowed slice; defer laser_vision clones; share string-table allocations via Rc<str>; precompute layout block scores; topo-sort via a max-heap - grammar load: intern names through a map; precompute the used-symbol set No behavior change; adds checkpoint max_frame_ref invariant tests.
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.
Summary
Stringeach time. Formatting a whole result does about 17 allocations.kindis kept as a&'static str, since tree-sitter already owns that name. Struct objects reserve their field slots up front. Materializing a result does about 25% fewer allocations.successors()returns a borrowed slice, the string table shares each string withRc<str>, layout scores are computed once, and the type sort uses a heap.Why
A performance review, double-checked by a second pass, found easy wins: one quadratic on the backtracking path, a lot of throwaway allocations when printing results, and many loops that could be a single map lookup. All 1068 tests pass. Nothing changes behavior.
Notes
Value(would add a lifetime to the publicValuetype).&mut selfin the diagnostics code).mem::takein grammar node-shape code and per-body type inference — both change results, not just speed.unsafe, and the CLI doesn't use that path).