Skip to content
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

Validation promise performance #2052

Closed
DaddyWarbucks opened this issue Jul 8, 2023 · 0 comments
Closed

Validation promise performance #2052

DaddyWarbucks opened this issue Jul 8, 2023 · 0 comments

Comments

@DaddyWarbucks
Copy link
Contributor

DaddyWarbucks commented Jul 8, 2023

When using large, deeply nested schemas with lots of sync tests and only one async test, calling schema.validate() converts ALL tests to promises. This means that a schema with 100 sync validation tests (or nested tests) and one async validation test will use 101 promises to validate the schema.

I first noticed this issue when validating an array of 5,000 items with a rather large nested schema but only one async validation that was actually a noop. The validation would take up to 10 seconds. But when removing that validation and calling validateSync the time dropped to roughly 2 seconds.

The included PR updates the createValidation function in a manner that only pushes validations onto the event loop if they are a promise, otherwise it validates as a sync function. This avoids scheduling sync work in the event loop and leads to some major performance improvements.

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

No branches or pull requests

1 participant