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

fix: performance improvement (#2043) #2044

Merged
merged 4 commits into from Jul 28, 2023

Conversation

tedeschia
Copy link
Contributor

@tedeschia tedeschia commented Jul 3, 2023

Resolves performance issues for large data validation described on #2043 :

  • Arrays of ValidationError
    • Mutate the array with splice instead of using concat
  • ValidationError class
    • Add the new option "disableStackTrace" to stop capturing stack trace when instantiating ValidationError
    • Stop ValidationError extending Error, so no need to call super() when instantiating ValidationError

package.json Outdated Show resolved Hide resolved
src/schema.ts Outdated Show resolved Hide resolved
src/schema.ts Outdated Show resolved Hide resolved
src/schema.ts Outdated Show resolved Hide resolved
src/ValidationError.ts Outdated Show resolved Hide resolved
tedeschia and others added 3 commits July 7, 2023 15:03
Co-authored-by: Jason Quense <monastic.panic@gmail.com>
Co-authored-by: Jason Quense <monastic.panic@gmail.com>
@tedeschia
Copy link
Contributor Author

@jquense I think I made all requested changes, is there anything pending from me to approve the PR?

@jquense jquense merged commit ee1b731 into jquense:master Jul 28, 2023
1 check failed
@jquense
Copy link
Owner

jquense commented Jul 28, 2023

thanks!

jquense added a commit that referenced this pull request Jul 28, 2023
jquense added a commit that referenced this pull request Jul 28, 2023
@jquense
Copy link
Owner

jquense commented Jul 28, 2023

@tedeschia unfortunately this broke a lot of tests so i had to revert. If you want re-open and fix the failures i'll happily merge it again

@tedeschia
Copy link
Contributor Author

tedeschia commented Jul 28, 2023 via email

@tedeschia
Copy link
Contributor Author

@jquense the reason of tests failing is having changed the inheritance of ValidationError from Error.
I broke that inheritance because thowsands of "new Error()" was one of the main time consuming tasks in my profiling, and changed by an implementation of Error interface.

But that change make this kind of assertion to fail:
".rejects.toThrowError()"

Reverting "ValidationError implements Error" to "ValidationError extends Error" makes all the tests run OK.

Do you think I can keep the ValidationError change and rewrite the tests to handle this new kind of ValidationError object? If you are OK I can work on it.

Thanks!

@jquense
Copy link
Owner

jquense commented Jul 28, 2023

The concern here is in our tests broke because it doesn't recognize the throw object as an error then lots of other ppls tests are going to break as well. I don't think the inheritance is necessarily the problem, it might just be shape of the error is different in an important way (less the stack trace)

@tedeschia
Copy link
Contributor Author

@jquense yes you are right. inspecting jest toThrow code I noticed it checks for error object this way:

switch (Object.prototype.toString.call(value)) {
    case '[object Error]':
    case '[object Exception]':
    case '[object DOMException]':
      return true;
    default:
      return value instanceof Error;
  }

so adding [Symbol.toStringTag] = 'Error' to ValidationError class did the trick.
I have created a new PR #2072 with this fix.

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.

None yet

2 participants