DEV Community

JavaScript schema library from the Future 🧬

Dmitry Zakharov on February 21, 2025

ReScript Schema - The fastest parser in the entire JavaScript ecosystem with a focus on small bundle size and top-notch DX. Why did you not hear a...
Collapse
 
1ce profile image
Sby β€’

Nice work! Definitely will consider it next time I need a parser or a validator.
By the way, since you're familiar with Typia, have you by any chance seen a recent post by Typia's author about its performance with the Bun runtime being 20 times slower?
Would you perhaps have any comments on that? I'm also interested in how ReScript Schema performs with different runtimes (Node, Deno, Bun, browser)

Collapse
 
dzakh profile image
Dmitry Zakharov β€’

Interesting, this is a new one. Just read it and left a like dev.to/samchon/bun-is-up-to-20x-sl...

Node.js, Deno and Browser are fine; the only problem is with Bun, which you can see in the community benchmark moltar.github.io/typescript-runtim...

I can see many comments in the article where people claim that it's a Typia specific problem, but Typia is a codegen library, and it doesn't do anything special in runtime. This means if you write a function like (input) => "string" === typeof input by hand and run it multiple times, it'll execute multiple times slower in Bun than in any other runtime.

Collapse
 
jeff_pegg_97454b18784a524 profile image
Jeff Pegg β€’

Hi Dmitry, nice article. In your last code example showing the under the hood code, on the 3rd line it says e7, where does the capital I come from or is that a typo?

Collapse
 
dzakh profile image
Dmitry Zakharov β€’

Hm, this looks like a copy-paste bug from Google Docs where I initially written the article. It should be a lower case i. As for e it comes from the function context and used for safe embedding to eval code.

Collapse
 
jeff_pegg_97454b18784a524 profile image
Jeff Pegg β€’

I didn't even notice it stripped the brackets and parenthesis from my comment.
e[7](I)

Collapse
 
dhruvgarg79 profile image
Dhruv garg β€’

what about comparison with typebox? It's also much faster than zod.

Collapse
 
dzakh profile image
Dmitry Zakharov β€’

This is actually very good, and it's very mature. I actually had a misunderstanding about it being a worse version of Typia, but after double-checking the docs, I was really impressed by it.

In the benchmark, you can indeed see that it's fast moltar.github.io/typescript-runtim...

But there are some trade-offs that are solved in ReScript Schema:

  • Optimised check only supports validation, not parsing with data transformations
  • I find the DX of ReScript Schema to be more friendly for web developers. Also, reshaping and reversing are still unbeaten
  • The TypeBox packages size is huge, making it not the best fit for web development github.com/sinclairzx81/typebox?ta...

So, at the moment of writing the article I think ReScript Schema is a better library if you use it for Web, but for server-side TypeBox is more mature and provides more flexibility and features. Although there are still some features of ReScript Schema you might want to use, which are not a part of TypeBox πŸ˜‰

ReScript Schema v10 is coming, which will improve the flexibility similar to TypeBox while boosting DX even more, exceeding Zod and ArkType levels 😁

Collapse
 
dzakh profile image
Dmitry Zakharov β€’

Ok, I decided to double-check the package size table from their docs and it actually happened that the package size is not big bundlephobia.com/package/@sinclair...

Another thing to compare is the much more readable error messages by default in ReScript Schema.

Collapse
 
alexdev404 profile image
Immanuel Garcia β€’

So why even use this if you can just use Zod or Valibot, bypassing any or all of that eval magic you did just for a few extra kilobytes?

Collapse
 
dzakh profile image
Dmitry Zakharov β€’ β€’ Edited

Eval actually makes the size bigger πŸ˜…

There are some unique features you can't find in any other library together:

  • Nice API with good DX
  • Top performance
  • Ability to conveniently and efficiently transform data when you parse
  • Ability to transform data without validation
  • Ability to get schema for the output type
  • Flexible set of operations

If you don't need it, then use Zod or Valibot. Both of them are good libraries I like.

Collapse
 
retakenroots profile image
Rene Kootstra β€’

Hmm very interesting article. Though when i read eval it raised some concerns. Nonetheless good job.

Collapse
 
dzakh profile image
Dmitry Zakharov β€’

It's indeed good to be aware of this because if you build for serverless or some widget that is embedded as a CDN to someone else website (CSP) there might be problems. But as I said, this is ~1% of use cases.

Also, ArkType uses eval, and according to Colin's words, he plans to add Eval mode to Zod v4.

Ideally, there should be a fallback mode to be able to work without Eval when it's not supported. I actually recently got an idea of how to implement it without reducing the quality of the library. But it'll probably take several months for me to implement.

Collapse
 
jesterly profile image
Jester Lee β€’

Very cool, and thanks for the heads up about eval. It's a shame we can't use this in browser extensions because eval is not allowed in MV3 :-(.

Collapse
 
ravi-coding profile image
Ravindra Kumar β€’

Awesome !