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

perf: improve validation sync and async by replacing forEach with classic for loops #11414

Merged
merged 2 commits into from
Feb 17, 2022

Conversation

Uzlopak
Copy link
Collaborator

@Uzlopak Uzlopak commented Feb 17, 2022

It is basically replacing the forEach with classic for loop

before

MONGOOSE_DEV=1 node validate
invalid x 23,482 ops/sec ±3.63% (89 runs sampled)
valid x 75,238 ops/sec ±0.58% (91 runs sampled)

after

MONGOOSE_DEV=1 node validate
invalid x 27,460 ops/sec ±0.91% (89 runs sampled)
valid x 76,128 ops/sec ±0.69% (93 runs sampled)

if (validating[path]) {
return;
continue;
}

validating[path] = true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to keep track if we are validated a path already?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall exactly, but it has something to do with subdocuments or nested paths. Having both the parent path and child path modified at the same time can cause double validation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

God bless unit tests.
In an ideal world, we can not do that and see what test fails.

@vkarpov15 vkarpov15 added this to the 6.2.3 milestone Feb 17, 2022
@vkarpov15 vkarpov15 merged commit a499c91 into Automattic:master Feb 17, 2022
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

3 participants