Code Monkey home page Code Monkey logo

Comments (4)

sinclairzx81 avatar sinclairzx81 commented on May 25, 2024 2

@moltar Hey, awesome, that would be great ! :)

Will keep an eye out for #497, I'm very curious to see how the AJV validation stacks up against specialized TS type validation.

Many Many Thanks!
S

from typescript-runtime-type-benchmarks.

moltar avatar moltar commented on May 25, 2024 1

Just for a bit of context. I actually manage this project https://github.com/sinclairzx81/typebox that implements the JSON schema specification but doesn't actually implement any runtime validation logic.

Yup yup, I am a fan of your work! :)

TypeBox doesn't currently meet either criteria for benchmarking as it offers no validation function

Yup, I tried it in #97 😁

It's an interesting one. In all, I do think a pure Ajv test would give a good indication of how standard JSON validation holds up against libraries who chose to implement internal custom validation logic.

I kinda agree and maybe we'll relax the criteria a bit after we finish #497 which opens up the possibility for different groups of tests.

from typescript-runtime-type-benchmarks.

moltar avatar moltar commented on May 25, 2024

Hey @sinclairzx81!

Does ajv fit into the criteria outlined here? https://github.com/moltar/typescript-runtime-type-benchmarks#criteria

Also, I think some packages do use ajv internally. You can see which ones by doing npm ls ajv in the repo.

from typescript-runtime-type-benchmarks.

sinclairzx81 avatar sinclairzx81 commented on May 25, 2024

Hey @moltar, thanks for the quick response.

Does ajv fit into the criteria outlined here? https://github.com/moltar/typescript-runtime-type-benchmarks#criteria

Ah I didn't see the criteria section. Thanks for linking that.

  • These packages are capable of validating the data for type correctness (Yes)
  • It has a validator function or method that returns a valid type casted value or throws. (Not directly)

I guess on the second point, Ajv doesn't quite meet the criteria, but it is very close. The following 4 line function would be enough for Ajv to fit the criteria.

// The following deserializes the given string and returns T if matching the given schema, otherwise throw.
function deserialize<T = unknown>(schema: any, data: string): T {
    const ajv = new Ajv();
    const obj = JSON.parse(data)
    if(!ajv.validate(schema, obj)) throw 
    return obj
}

Just for a bit of context. I actually manage this project https://github.com/sinclairzx81/typebox that implements the JSON schema specification but doesn't actually implement any runtime validation logic. Conceptually, the library is similar to io-ts, zod and runtypes (where it implements static inference) but whose runtime performance is measured by that of the underlying JSON schema validator.

TypeBox doesn't currently meet either criteria for benchmarking as it offers no validation function, and requires a JSON schema validator of the users choosing to runtime type check. It's an outlier because it's conceptually serving the same role as io-ts, zod and runtypes but whose performance is tied to that of the JSON schema validator. So the only way to benchmark TypeBox would be to benchmark JSON schema validators. I expect this would be true for other test cases dependent on Ajv.

It's an interesting one. In all, I do think a pure Ajv test would give a good indication of how standard JSON validation holds up against libraries who chose to implement internal custom validation logic.

Open to your thoughts!
Cheers
S

from typescript-runtime-type-benchmarks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.