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
Removing ZodError inheritance from the Error class doubles or even triples the op/sec for invalid benchmark tests. This is because a stack trace doesn't need to be collected, which is useless for parse errors anyway. It is pretty easy-to-do modification. The only con is that it breaks compatibility e.g. result.error instanceof Error which is somehow weird so I think it is worth it.
Invalid Tests
Error Subclass (instanceof Error)
Standalone Class
z.enum: invalid
131,440 ops/sec
250,984 ops/sec
long z.enum: invalid
118,232 ops/sec
224,574 ops/sec
z.undefined: invalid
127,715 ops/sec
260,896 ops/sec
z.literal: invalid
125,889 ops/sec
252,896 ops/sec
z.number: invalid type
122,146 ops/sec
259,295 ops/sec
z.number: invalid number
125,977 ops/sec
266,057 ops/sec
z.date: invalid
124,918 ops/sec
255,595 ops/sec
z.date: invalid min
123,008 ops/sec
249,733 ops/sec
z.date: invalid max
123,179 ops/sec
248,390 ops/sec
z.symbol: invalid
143,278 ops/sec
349,873 ops/sec
z.string: invalid: null
142,573 ops/sec
344,606 ops/sec
z.object: empty: invalid: null
141,122 ops/sec
346,413 ops/sec
z.object: short: invalid: null
141,898 ops/sec
346,534 ops/sec
z.object: long: invalid: null
136,760 ops/sec
347,982 ops/sec
Another +10% op/sec (V8 optimizations) on invalids just by changing handleResult's:
{
success: false,
get error() {
if (this._error)
return this._error;
const error = new ZodError(ctx.common.issues);
this._error = error;
return this._error;
},
}
to
return {
success: false,
error: new ZodError(ctx.common.issues)
};
Btw I'm showing just weak spots. Not proposal code.
The text was updated successfully, but these errors were encountered:
Removing ZodError inheritance from the Error class doubles or even triples the op/sec for invalid benchmark tests. This is because a stack trace doesn't need to be collected, which is useless for parse errors anyway. It is pretty easy-to-do modification. The only con is that it breaks compatibility e.g.
result.error instanceof Error
which is somehow weird so I think it is worth it.instanceof Error
)z.enum: invalid
long z.enum: invalid
z.undefined: invalid
z.literal: invalid
z.number: invalid type
z.number: invalid number
z.date: invalid
z.date: invalid min
z.date: invalid max
z.symbol: invalid
z.string: invalid: null
z.object: empty: invalid: null
z.object: short: invalid: null
z.object: long: invalid: null
Another +10% op/sec (V8 optimizations) on invalids just by changing handleResult's:
to
Btw I'm showing just weak spots. Not proposal code.
The text was updated successfully, but these errors were encountered: