-
Notifications
You must be signed in to change notification settings - Fork 802
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: Nested validations optimization #1048
fix: Nested validations optimization #1048
Conversation
Bump |
@aaleksandrov, could you rebase/merge this and get rid of the irrelevant changes in this PR? |
Hi @braaar |
In my opinion, the diff is all that matters and squashing and merging is the better way to deal with PRs, but I'm not sure if that is the opinion of the maintainers. |
2ef8ff0
to
0da8f89
Compare
const filteredForInheritedMetadatasSearch = []; | ||
for (const [key, value] of this.validationMetadatas.entries()) { | ||
if (targetConstructor.prototype instanceof key) { | ||
filteredForInheritedMetadatasSearch.push(...value); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it faster to loop over the prototype chain and look up the contructors in the map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right, but this I did not fix in the new PR. I just merged it in its current state for the performance gains. If you are up for the task, please implement it in a new PR.
You have merged back the diverged branch in your PR, as a result, I cannot clean this, I have cherry-picked your commit and opened a new PR. Superset by #1825 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
This optimizes performance of all validations and closes #343.
For example in my company we have 50+ complex models so
MetadatStorage.validationMetadatas
is array of ~5000 elements,MetadatStorage.constraintMetadatas
is an array of 2500 elements. Validator loops over these arrays multiple times, so it takes 5+ seconds to validate a batch of 550 objects.Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passesDidn't add any tests because my PR is pure refactoring of
MetadatStorage
, functionality is covered by tests alreadyFixes
fixes #343
Running tests in my company's project normally
Running tests in my company's project with this PR (42% performance improvement)