fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
6.32k stars 204 forks source link

Are you planning to add TypeCompiler.Compile just like typebox, to achieve high performance? #934

Open cit-gif opened 2 days ago

cit-gif commented 2 days ago

Example: https://github.com/sinclairzx81/typebox?tab=readme-ov-file#typecompiler

fabian-hiller commented 1 day ago

I have similar ideas with a build time compiler in mind, but at the moment it is not feasible in terms of time. I can see that TypeBox and others are much faster, but Valibot is still not slow and probably not the bottleneck if your application has performance problems. It is also important to mention that the speed of most of these high performance schema libraries is not "free". There are drawbacks. For example, many of them only check the properties of an object you define and return the original object. This could be a security problem if you put this object in your database, as it could contain malicious data. When I have more time, I will probably write a blog post about the performance of schema libraries.

sinclairzx81 commented 1 day ago

There are drawbacks. For example, many of them only check the properties of an object you define and return the original object. This could be a security problem if you put this object in your database, as it could contain malicious data. When I have more time, I will probably write a blog post about the performance of schema libraries.

FYI, there isn't a need to modify an object if the schematic outright prohibits additional data (additionalProperties: false). This is actually better for servers / databases as they can flat out reject malformed data (meaning a sender is mandated by the schematic to send correct data). In this regard, no provisions are made to transform a senders payload to match a target schematic. This is the principle applied in high performance validators.

Extra value processing (on top of Check), be it culling additional properties, value coercion, transforms or other kinds of processing is where bottlenecks are going to occur. TypeBox supports uncompiled versions of these, but the jury is still out on the most efficient implementation for each kind of operation. This said, Ajv still stands as one of the best integrated implementations for extra value processing. If you're looking to publish blog material on the topic of high performance validation + additional operations, Ajv would be a good thing to research.

Anyway, found this issue while browsing for TypeBox issues, and thought I'd leave a comment. Food for thought. Cheers S