Skip to content

Optimize Drizzle validator types#4424

Merged
AndriiSherman merged 9 commits intodrizzle-team:mainfrom
L-Mario564:validators-optimization
May 9, 2025
Merged

Optimize Drizzle validator types#4424
AndriiSherman merged 9 commits intodrizzle-team:mainfrom
L-Mario564:validators-optimization

Conversation

@L-Mario564
Copy link
Copy Markdown
Contributor

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.

@L-Mario564 L-Mario564 changed the base branch from beta to main April 17, 2025 16:47
Comment thread drizzle-orm/src/relations.ts Fixed
@L-Mario564 L-Mario564 force-pushed the validators-optimization branch from 5c177fa to 49e6b70 Compare April 17, 2025 17:05
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',
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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!

@AndriiSherman AndriiSherman merged commit 6c9e484 into drizzle-team:main May 9, 2025
26 checks passed
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.

[BUG]: Buffer is not defined using drizzle-arktype client side with vite

4 participants