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
perf(checker): insert into owned type vectors in place - #45
Four union/intersection callers already own their Vec<TypeId>, but insert_type clones the whole slice on every call, including when the type is already present.
Add insert_type_into for these callers. It keeps the buffer on a hit and inserts into it on a miss, avoiding the unconditional replacement-vector allocation and copy. The borrowed-slice helper remains available to its other callers. Rust scope: +14 / -6 lines across two files.
Why behavior stays the same
The helper invokes the same search_union_types once on the same elements. This preserves comparison order and lazy symbol-ID effects. It inserts at the same returned index and returns the same inserted/not-inserted result. All four changed callers own their vectors; the resulting element order and duplicate handling are unchanged. Vec::insert can still reallocate and shift elements on a miss.
This PR contains only the owned-vector change. Its correctness argument is the direct search/insertion correspondence above; no dedicated Lean proof is claimed.
Validation and evidence
Applied independently to bf34f21ae40b221ea9def389778d2f90ec950398; changed files pass rustfmt with Rust 1.93.0. Independent static review is attached.
Historical combined candidate: 133,390 compiler/conformance checks passed; 1,728 explicit skips. The default suite had 1,529 passes plus two API-session failures that passed on the same binary after a macOS socket-path correction. npm: 879 passes on each side. Workspace: 629 passes and one unchanged watch failure. Original failures and skips remain in the attached records.
Those results used the earlier parent 9f6ee6d147de1f8216c967e2a966cacbac295984 and included other optimizations. They are not test results for this independent PR head. No standalone speedup or memory percentage is claimed.
Draft pending the light-path checks in docs/typechecker-accountability.md: existing focused tests, protected goport comparison against the latest accepted revision with no lost passes, and byte-equal Query/Hono/zod/effect output. Exact-head Cargo build/runtime checks, clippy and CI remain pending. This follows the validation pattern in #31; the attached evidence preserves what has actually run.
Note
Add in-place type insertion to checker.Checker to avoid vector replacement
Adds insert_type_into variants in checker_p29.rs that mutate the existing owned vector and skip creating a replacement vector when the type is already present. The union-origin, subtype-reduction, and primitive-union intersection routines in checker_p28.rs and checker_p29.rs now use the in-place helper. Semantics are unchanged: it still searches union types, inserts only when absent, and keeps the undefined/missing handling as-is.
Thank you for this PR and for the clear write-up. We checked it against the Go insertType and the port. It is correct: same search, same insert position, same result. We built it on top of current main and ran it against our protected set. The output was byte-equal on Query, Hono, zod, Effect and the T3 Code server, and the goport tests lost no passes (181,914 retained). The measured gain is 0.01 to 0.05 percent single-thread instructions, with no change in peak memory. Our bar for speed changes is about 1 percent instructions, 2 percent wall or 5 percent peak memory, so we will close this one. Thanks again for the careful work.
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
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.
Four union/intersection callers already own their
Vec<TypeId>, butinsert_typeclones the whole slice on every call, including when the type is already present.Add
insert_type_intofor these callers. It keeps the buffer on a hit and inserts into it on a miss, avoiding the unconditional replacement-vector allocation and copy. The borrowed-slice helper remains available to its other callers. Rust scope: +14 / -6 lines across two files.Why behavior stays the same
The helper invokes the same
search_union_typesonce on the same elements. This preserves comparison order and lazy symbol-ID effects. It inserts at the same returned index and returns the same inserted/not-inserted result. All four changed callers own their vectors; the resulting element order and duplicate handling are unchanged.Vec::insertcan still reallocate and shift elements on a miss.This PR contains only the owned-vector change. Its correctness argument is the direct search/insertion correspondence above; no dedicated Lean proof is claimed.
Validation and evidence
bf34f21ae40b221ea9def389778d2f90ec950398; changed files passrustfmtwith Rust 1.93.0. Independent static review is attached.9f6ee6d147de1f8216c967e2a966cacbac295984and included other optimizations. They are not test results for this independent PR head. No standalone speedup or memory percentage is claimed.Draft pending the light-path checks in
docs/typechecker-accountability.md: existing focused tests, protected goport comparison against the latest accepted revision with no lost passes, and byte-equal Query/Hono/zod/effect output. Exact-head Cargo build/runtime checks, clippy and CI remain pending. This follows the validation pattern in #31; the attached evidence preserves what has actually run.Note
Add in-place type insertion to
checker.Checkerto avoid vector replacementAdds
insert_type_intovariants in checker_p29.rs that mutate the existing owned vector and skip creating a replacement vector when the type is already present. The union-origin, subtype-reduction, and primitive-union intersection routines in checker_p28.rs and checker_p29.rs now use the in-place helper. Semantics are unchanged: it still searches union types, inserts only when absent, and keeps the undefined/missing handling as-is.Macroscope summarized 34ffee5.