Skip to content

Add TypeMap (Zod & Valibot) #1731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged

Add TypeMap (Zod & Valibot) #1731

merged 1 commit into from
Mar 14, 2025

Conversation

sinclairzx81
Copy link
Contributor

@sinclairzx81 sinclairzx81 commented Mar 14, 2025

Description

This PR adds a new library named TypeMap. This library is somewhat unique in that it JIT accelerates Zod and Valibot on TypeBox infrastructure. It also provides runtime and type level mapping for these libraries so should fit the benchmark criteria.

https://github.com/sinclairzx81/typemap

This PR also bumps Valibot to the 1.0.0-rc.4 release candidate.


Notes

The TypeMap library takes on Zod and Valibot as peerDependencies. I am currently tracking the latest versions of these libraries, but will need to be mindful when new majors are pushed (as I may need to bump the peer dependency version ranges in TypeMap). If there are any issues though, feel free to ping me (peer dependencies can get a bit awkward)

Additionally, depending on the degree of upstream changes taking place in these libraries, if changes are significant and can't be trivially reconciled in TypeMap via version ranges, I would be happy to omit TypeMap from these tests to allow the new versions through (with particular note to the upcoming Zod 4).

Submitting for consideration and review.

Testing

Tested via

$ npm test  # preflight tests

$ npm start # full benchmark

Checklist

  • Conducted a self-review of the code changes.
  • Updated documentation, if necessary.
  • Added tests to validate the functionality or fix.

Copy link
Owner

@moltar moltar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, excited to see the results!

@moltar moltar requested review from DarkGL and hoeck March 14, 2025 09:47
@hoeck
Copy link
Collaborator

hoeck commented Mar 14, 2025

Wow, cool project 😄.

The TypeMap library takes on Zod and Valibot as peerDependencies. I am currently tracking the latest versions of these libraries, but will need to be mindful when new majors are pushed (as I may need to bump the peer dependency version ranges in TypeMap). If there are any issues though, feel free to ping me (peer dependencies can get a bit awkward)

Additionally, depending on the degree of upstream changes taking place in these libraries, if changes are significant and can't be trivially reconciled in TypeMap via version ranges, I would be happy to omit TypeMap from these tests to allow the new versions through (with particular note to the upcoming Zod 4).

That will indeed cause problems in the future.

But these can be (easily?) mitigated by keeping all modules in isolation as some kind of multi-package repository where each library is installed and benchmarked separately including all its dependencies and its own typescript and whatever it needs, see #899.

I'm too lazy right now to do anything (may others do the first step) but I know that I'd jump in once there is enough pressure because things are falling apart 😁.

@sinclairzx81
Copy link
Contributor Author

@hoeck Hi, thanks :)

But these can be (easily?) mitigated by keeping all modules in isolation as some kind of multi-package repository where each library is installed and benchmarked separately including all its dependencies and its own typescript and whatever it needs, see #899.

Hey yeah! Having a separate project / isolated node_modules directory per test case would be an amazing setup :) Isolating each test as a isolate project should fully mitigate any issues relating to cross linked peer dependencies (each project just installing what it needs). I'm not too familiar with progen, but it does seem like it could offer some test automation options. I might do some further reading on it (it actually looks quite interesting)

As for TypeMap, and depending on timings, I am keeping track of the current two peer dependencies (Valibot, Zod). These dependencies should update fine for revisions and minor semver ticks, but am somewhat mindful on the upcoming Zod 4 release (major semver). Depending on how things go, if there are problems updating to Zod 4, I would be totally fine omitting TypeMap from the tests cases just to let Zod 4 test cases go through (that would be more important I think)

TypeMap will be updated to Zod 4 when it's out, it mostly just comes down to timings :)

Cheers!
S

@hoeck hoeck merged commit 0368e8e into moltar:master Mar 14, 2025
10 checks passed
@sinclairzx81
Copy link
Contributor Author

@hoeck @moltar Hi,

Just checked back this morning to have a look at the numbers, seems like the CI failed to publish the website. Not sure if this is related to this PR or general CI fault, but the benchmarks are currently offline.

Would it be possible to re-run the job?

@hoeck
Copy link
Collaborator

hoeck commented Mar 15, 2025

but the benchmarks are currently offline.

experienced that too .. but that was because unpgk.com had long response times / timeouts even. Should switch to using Vite rather soon bc. its easier to use and does not depend on an external service to load dependencies.

Would it be possible to re-run the job?

There was again some kind of race condition, the pr.yml action failed to commit the results because I think some other job ran as well that also committed something.

But that is not an issue as the regular automatic dependabot updates also run all benchmarks. And there where was one those updates already and you can see that typemap/zod and typemap/valibot results are present in the results json.

Now, they do not show up the results. To me it looks like the pages deploy happens before the results are being committed and pushed to master.

TLDR: I re-ran the github pages action and now your results show up despite unpgk slowing down the loading of the site.

@hoeck
Copy link
Collaborator

hoeck commented Mar 15, 2025

Oh and BTW the results for your zod wrapper are insane 😄

@sinclairzx81
Copy link
Contributor Author

@hoeck Hi!

I re-ran the github pages action and now your results show up despite unpgk slowing down the loading of the site.

Hey, thanks for the follow up! Can confirm the website loaded up ok. All good :)

Oh and BTW the results for your zod wrapper are insane 😄

Nice! The new tests benchmarked quite well. The mappings should let these libraries validate with roughly the same performance as TypeBox JIT. There's a bit of upfront overhead mapping the libraries over to schematics, but once mapped, they should be nice and fast!

Thanks again!
S

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants