-
Notifications
You must be signed in to change notification settings - Fork 935
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
Slow performance with large arrays #2043
Comments
That would probably be pretty easy to optimize if you want to take a stab at it? |
Alternatively, you could at abortEarly: true to fail fast, since it's unlikely you need 40,000 of probably the same error |
abortEarly is not an option for me. It's nos necessarily all the same errors (this case was just an example) and I need to give the user a feedback for every row. I tried with this change and it was solved:
do you want me to send a PR? I'm also measuring other bottlenecks and found that ValidationError constructor also takes its time (considering thousands of it) at: |
I'd definitely be open to a PR for both, maybe we could toggle the stack traces off via an option, tbh the stack isn't really useful for validation error |
With the proposed optimizations in #2044, the performance is significantly improved, and there is no exponential performance degradation when the array grows. |
* fix: performance improvement (#2043) * Update src/ValidationError.ts Co-authored-by: Jason Quense <[email protected]> * Apply suggestions from code review Co-authored-by: Jason Quense <[email protected]> * fix PR comments --------- Co-authored-by: Jason Quense <[email protected]>
* fix: performance improvement (#2043) * Update src/ValidationError.ts Co-authored-by: Jason Quense <[email protected]> * Apply suggestions from code review Co-authored-by: Jason Quense <[email protected]> * fix PR comments * #2043 add Error toStringTag to custom ValidationError class --------- Co-authored-by: Jason Quense <[email protected]>
…ack trace is required
Hi @jquense, this is me again with this performance improvement! |
…n performance (#2142) * #2043 add ValidationErrorNoStack to improve error creation performance * Consolidate * #2043 remove ValidationErrorNoStack references --------- Co-authored-by: jquense <[email protected]>
I need to validate some large arrays (about 100,000 items). When there are lots of validation errors, the validation process takes a long time to run.
I reproduced the issue in CodeSandbox: https://codesandbox.io/s/yup-performance-test-6jxn5m?file=/src/index.js
There I defined an array schema of required numbers and run the validation for some datasets to measure the performance. This is the result:
Validation of 5000 items took 169.6 ms
Validation of 10000 items took 320.1 ms - 88.7% increase vs last fun
Validation of 20000 items took 985.1 ms - 207.7% increase vs last fun
Validation of 40000 items took 5,034.8 ms - 411.1% increase vs last fun
It seems to be an exponential increase of time to process the validations.
Doing some profiling, it seems that the issue is in this line of ValidationError class:
this.inner = this.inner.concat(err.inner.length ? err.inner : err);
The text was updated successfully, but these errors were encountered: