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

Performance improvements for insertMany() #14724

Merged
merged 9 commits into from
Jul 10, 2024
Merged

Conversation

vkarpov15
Copy link
Collaborator

@vkarpov15 vkarpov15 commented Jul 3, 2024

Summary

The big changes are:

  1. a _skipParallelValidateCheck option for validate(). Looks like creating a new ParallelValidateError() each time is relatively expensive, and unnecessary for insertMany() since the user won't have access to the document references anyway outside of middleware.
  2. Skip $toObject() in favor of $__toObjectInternal(), which skips options processing and only does a shallow clone, when using insertMany() on documents which only have primitive values (no subdocs, nested paths, or arrays).

Before this PR:

$ node gh-14719.js 
{
  "Average insertMany time ms": 54.99
}

After this PR:

$ node gh-14719.js 
{
  "Average insertMany time ms": 20.66
}

Looking at about 2.5x performance improvement.

Potential alternative would be to change this.$__.validating to use a boolean instead of an error instance, will investigate.

Examples

@vkarpov15 vkarpov15 marked this pull request as draft July 3, 2024 20:06
lib/document.js Outdated Show resolved Hide resolved
@vkarpov15 vkarpov15 marked this pull request as ready for review July 9, 2024 20:43
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

Looks good to me, one minor suggestion

lib/document.js Outdated Show resolved Hide resolved
@vkarpov15 vkarpov15 added this to the 8.5.1 milestone Jul 10, 2024
@vkarpov15 vkarpov15 merged commit d30a3b9 into master Jul 10, 2024
46 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-14719 branch July 10, 2024 15:56
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.

3 participants