In another community, someone asked me the reason why such performance gap.
It's my answer and I also paste it here dev.to
"15,000x faster" is just a benchmark program result and such different is not weird considering principle of v8 optimization. It is enough reasonable and descriptable.
typia performs AOT compilation through TypeScript API
ajv and typebox performs JIT compilation through eval() function
class-validator abuses for in statement and dynamic [key, value] allocation in every step
V8 engine optimizes object construction by converting to a hidden class and avoid hash map construction for taking advantages of static class definition. However, if for in statement or dynamic key allocation being used, v8 cannot optimize the object.
The secret of extremely slow validation speed of class-validator is on there. class-validator utilizes the un-optimizable in every process.
for in statement on metadata when iterating raw data to transform
dynamic allocation when transforming to a class instance
dynamic statement on metadata (of decorator)
for in statement when validation
For reference, ajv and typebox are using JIT compilation, generating optimized code in runtime through eval() function (or new Function(string) statement). In v8 engine, priority of optimization is the lowest and it is the principle reaon why typia is faster than such ajv and typebox libraries.
Another reason is how to optimize object accessment. You can see the detailed story about it from below link (this article)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In another community, someone asked me the reason why such performance gap.
It's my answer and I also paste it here
dev.to"15,000x faster" is just a benchmark program result and such different is not weird considering principle of v8 optimization. It is enough reasonable and descriptable.
typiaperforms AOT compilation through TypeScript APIajvandtypeboxperforms JIT compilation through eval() functionclass-validatorabuses for in statement and dynamic [key, value] allocation in every stepV8 engine optimizes object construction by converting to a hidden class and avoid hash map construction for taking advantages of static class definition. However, if
for instatement or dynamic key allocation being used, v8 cannot optimize the object.The secret of extremely slow validation speed of
class-validatoris on there.class-validatorutilizes the un-optimizable in every process.For reference,
ajvandtypeboxare using JIT compilation, generating optimized code in runtime througheval()function (ornew Function(string)statement). In v8 engine, priority of optimization is the lowest and it is the principle reaon whytypiais faster than suchajvandtypeboxlibraries.Another reason is how to optimize object accessment. You can see the detailed story about it from below link (this article)