-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve the performance of z.nativeEnum #4341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for guileless-rolypoly-866f8a ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
WalkthroughThis update adds two new benchmark suites for native enum parsing to both Deno and source benchmark files. It also tweaks the internal implementation of the Changes
Sequence Diagram(s)sequenceDiagram
participant BenchmarkSuite
participant ZodNativeEnum
participant Util
BenchmarkSuite->>ZodNativeEnum: parse(input)
ZodNativeEnum->>Util: getValidEnumValues(enumDef)
Util-->>ZodNativeEnum: validValues
ZodNativeEnum->>ZodNativeEnum: check input against validValues
ZodNativeEnum-->>BenchmarkSuite: result (success or error)
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (11)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
The previous implementation converted the enum into an array of values on each parse call, even though the array was never used in the happy path. This was especially problematic on large enums, since the work done was proportional to the size of the enum. I also removed an extra call to `util.objectValues` on the failure path, since it seemed to be superfluous (`util.getValidEnumValues` already calls it). Before: z.nativeEnum: valid x 4,376,561 ops/sec ±0.65% (95 runs sampled) z.nativeEnum: invalid x 139,663 ops/sec ±6.37% (91 runs sampled) long z.nativeEnum: valid x 1,197,450 ops/sec ±0.25% (97 runs sampled) long z.nativeEnum: invalid x 116,181 ops/sec ±0.46% (96 runs sampled) After z.nativeEnum: valid x 10,978,553 ops/sec ±0.41% (98 runs sampled) z.nativeEnum: invalid x 143,931 ops/sec ±5.40% (93 runs sampled) long z.nativeEnum: valid x 9,783,582 ops/sec ±0.38% (99 runs sampled) long z.nativeEnum: invalid x 122,292 ops/sec ±0.48% (99 runs sampled)
8c7b5db
to
ded6dd3
Compare
The previous implementation converted the enum into an array of values on each parse call, even though the array was never used in the happy path.
This was especially problematic on large enums, since the work done was proportional to the size of the enum.
I also removed an extra call to
util.objectValues
on the failure path, since it seemed to be superfluous (util.getValidEnumValues
already calls it).Before:
After:
Summary by CodeRabbit
New Features
Refactor