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: Nested validations optimization #1048

Conversation

aaleksandrov
Copy link
Contributor

@aaleksandrov aaleksandrov commented May 1, 2021

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

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

Didn't add any tests because my PR is pure refactoring of MetadatStorage, functionality is covered by tests already

Fixes

fixes #343


Running tests in my company's project normally

  V1BulkProductsSpec
    ✓ should ingest 550 products as bulk (5938ms)

  1 passing (6s)

Running tests in my company's project with this PR (42% performance improvement)

   V1BulkProductsSpec
    ✓ should ingest 550 products as bulk (3451ms)
    
  1 passing (3.5s)

dependabot bot added 30 commits March 23, 2021 17:40
dependabot bot added 17 commits March 16, 2022 09:08
@b26
Copy link

b26 commented Jul 13, 2022

Bump

@braaar
Copy link
Member

braaar commented Oct 3, 2022

@aaleksandrov, could you rebase/merge this and get rid of the irrelevant changes in this PR?

@aaleksandrov
Copy link
Contributor Author

aaleksandrov commented Oct 22, 2022

Hi @braaar
I merged develop into my branch and resolved conflicts. However as you can see meanwhile develop was force-pushed so my PR still contains random commits. Do you want to me fix this (maybe creating a new PR would be the simplest way) or it's ok since changes are correct?

@braaar
Copy link
Member

braaar commented Oct 24, 2022

Hi @braaar I merged develop into my branch and resolved conflicts. However as you can see meanwhile develop was force-pushed so my PR still contains random commits. Do you want to me fix this (maybe creating a new PR would be the simplest way) or it's ok since changes are correct?

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.

src/metadata/MetadataStorage.ts Show resolved Hide resolved
src/metadata/MetadataStorage.ts Show resolved Hide resolved
Comment on lines +118 to +123
const filteredForInheritedMetadatasSearch = [];
for (const [key, value] of this.validationMetadatas.entries()) {
if (targetConstructor.prototype instanceof key) {
filteredForInheritedMetadatasSearch.push(...value);
}
}
Copy link
Contributor

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?

Copy link
Member

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.

@NoNameProvided NoNameProvided added the status: superset by another Issue or task being tracked/handled in a different issue. label Dec 3, 2022
@NoNameProvided
Copy link
Member

NoNameProvided commented Dec 3, 2022

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

@github-actions
Copy link

github-actions bot commented Jan 3, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: superset by another Issue or task being tracked/handled in a different issue.
Development

Successfully merging this pull request may close these issues.

perf: nested validation is slow
6 participants