Skip to content

perf(downgrader): look up a kept $ref's target only for a null anyOf pair in 3.1 to 3.0 - #89

Merged
dinwwwh merged 1 commit into
mainfrom
claude/project-thread-o6uyg9
Oct 24, 2026
Merged

dinwwwh merged 1 commit into
mainfrom
claude/project-thread-o6uyg9

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Oct 24, 2026

Copy link
Copy Markdown
Member

Requested by dinwwwh · project thread

#88 made 3.1 to 3.0 about 6 to 7% slower on $ref-heavy docs. Wall time on the bench doc went from 15.1 to 16.1 ms, and on Discord from 19.1 to 20.3 ms. CodSpeed's simulation mode doesn't catch it. The cause: convertSchemaRef resolved and checked the target of every kept schema $ref and added it to a WeakSet. Only a $ref beside the null branch of a two-branch anyOf ever reads that result.

This PR moves the check into mergeNullable, so it runs only for those pairs:

  • shared.ts exports find, the uncached pointer lookup that resolvePointer already wraps.
  • NULL_REJECTING_REFS and the check in convertSchemaRef are removed.
  • downgradeV30 passes root to mergeNullable. When the other branch is a kept $ref, mergeNullable checks the target in the input with rejectsNull(find(root, ref)). The input is always complete, so a cycle can't hand it a half-converted target.

Output doesn't change. All 256 tests and both snapshots (oRPC and corpus) pass with no edits. A separate check found byte-identical output to #88 on 41 real docs and 5,403 fuzz cases, with speed back to the pre-#88 level (15.4 ms and 19.0 ms). Locally, vitest bench puts this branch ahead of main on "generated api, 100 resources" in both runs. pnpm run check passes.


Generated by Claude Code

…pair in 3.1 to 3.0

#88 resolved and checked the target of every kept schema `$ref`, though only
a `$ref` beside the null branch of a two-branch `anyOf` reads the result.
`mergeNullable` now looks up that target in the input itself, which is
always complete, so the cycle concern goes away too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Ly7PKnnYtmt4xpZpzZuWp
@dinwwwh dinwwwh self-assigned this Oct 24, 2026
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Oct 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks


Comparing claude/project-thread-o6uyg9 (133ed5f) with main (0321f9d)

Open in CodSpeed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — the perf follow-up to #88 that defers the null-rejecting $ref check from conversion time to mergeNullable.

  • shared.ts — exports find, the uncached pointer lookup resolvePointer wraps, with a doc comment. No logic change.
  • v3.1-to-v3.0.ts — removes NULL_REJECTING_REFS and its fill in convertSchemaRef; mergeNullable now takes root and, for a kept $ref branch, checks rejectsNull(find(root, ref)).
  • Equivalence — old resolvePointer(ref, ctx) resolved against the same immutable input root that downgradeV30 now passes in, and $ref branches reaching the merge always originate from convertSchemaRef, so the WeakSet identity check and the getRef check cover the same branches. The full downgrader suite (252 tests) passes, including the existing kept-$ref and cyclic-schema cases.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh merged commit 8ad5613 into main Oct 24, 2026
11 checks passed
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