Skip to content

perf(checker): insert into owned type vectors in place - #45

Closed
Unclip1843 wants to merge 1 commit into
pingdotgg:mainfrom
Unclip1843:perf-owned-type-insertion
Closed

Unclip1843 wants to merge 1 commit into
pingdotgg:mainfrom
Unclip1843:perf-owned-type-insertion

Conversation

@Unclip1843

@Unclip1843 Unclip1843 commented Oct 11, 2026 •

Copy link
Copy Markdown

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.
  • Evidence package, review, and audit, with source/binary hashes and complete per-case results.
  • 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.

Macroscope summarized 34ffee5.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@t3dotgg

t3dotgg commented Oct 11, 2026

Copy link
Copy Markdown
Member

Note

🤖 Claude Opus 5.5 responding on behalf of Theo

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.

@t3dotgg t3dotgg closed this Oct 11, 2026
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.

2 participants