Optimize Drizzle validator types#4424
Merged
AndriiSherman merged 9 commits intodrizzle-team:mainfrom May 9, 2025
Merged
Conversation
5c177fa to
49e6b70
Compare
sixelasacul
reviewed
Apr 19, 2025
Comment on lines
+62
to
+64
| export const bufferSchema = type.unknown.narrow((value) => value instanceof Buffer).as<Buffer>().describe( // eslint-disable-line no-instanceof/no-instanceof | ||
| 'a Buffer instance', | ||
| ); |
There was a problem hiding this comment.
Hey @L-Mario564, I just wanted to let you know that I did a quick test for this specific schema in my codebase where I encountered the problem, and it does solve it. Thank you very much!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to improve TS language server performance for drizzle-zod, drizzle-valibot, drizzle-typebox and drizzle-arktype.
I used drizzle-arktype as the base for the optimization, getting around 20%-30% less type instantiations compared to before. There are some types that could be removed and have its logic placed in the types that use it, but I personally thought it hurts readability and removing such types only improves around 1%-2% (I did some testing/benchmarking), not too worth it IMO.
Other validator packages should have way less type instantions as well as removing some redudancy in some types, except for some types in drizzle-valibot since Valibot has more complex types, but it should see significant improvements too.
While I was doing this, I also fixed #4383 for drizzle-arktype.