Skip to content

faster initialization#5352

Merged
colinhacks merged 5 commits intomainfrom
faster-initialization
Oct 16, 2025
Merged

faster initialization#5352
colinhacks merged 5 commits intomainfrom
faster-initialization

Conversation

@colinhacks
Copy link
Copy Markdown
Owner

  • WIP
  • WIP

cursor[bot]

This comment was marked as outdated.

@vercel vercel Bot temporarily deployed to Preview – zod-v4 October 16, 2025 20:54 Inactive
cursor[bot]

This comment was marked as outdated.

@colinhacks colinhacks requested a review from Copilot October 16, 2025 20:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR focuses on optimizing the initialization performance of Zod schemas by reducing unnecessary computations during schema construction. The changes eliminate deferred attachment callbacks in favor of direct property assignments and streamline the initialization logic in the core $constructor function.

Key Changes:

  • Refactored $constructor to initialize _zod properties upfront and prevent duplicate initialization
  • Replaced deferred onattach callbacks with direct property assignments for format types (IPv4, IPv6, Base64, Base64URL)
  • Optimized prototype method binding using indexed loops instead of for-in loops

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/zod/src/v4/core/core.ts Core initialization logic optimized to set properties directly and avoid redundant work
packages/zod/src/v4/core/schemas.ts Removed onattach callbacks, replaced with direct property assignments; fixed constructor names and typos
packages/zod/src/v4/mini/iso.ts Corrected constructor names from internal $Zod* format to public ZodMini* format
packages/zod/src/v4/classic/schemas.ts Minor whitespace cleanup
packages/bench/*.ts Code formatting improvements and addition of initialization benchmark test
packages/bench/tsconfig.json Disabled unused variable/parameter checks for benchmark code
biome.jsonc Removed packages/bench from lint ignore list
play.ts Updated example to test uint32 parsing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@vercel vercel Bot temporarily deployed to Preview – zod-v4 October 16, 2025 22:27 Inactive
@colinhacks colinhacks merged commit 39f8c45 into main Oct 16, 2025
5 checks passed
@colinhacks colinhacks deleted the faster-initialization branch October 16, 2025 22:29
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