Skip to content

Performance: avoid cloning when saving document if minimize: false #15694

@vkarpov15

Description

@vkarpov15

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

In $__handleSave() we have the following:

  if (this.$isNew) {
    // send entire doc
    const obj = this.toObject(saveToObjectOptions);

However, if minimize: false, we don't need to run toObject(), we can just do const obj = this._doc because the MongoDB driver will clone and apply toBSON() anyway. This should significantly help performance.

Re: #8024, let's implement this functionality first and make sure it works as intended before considering making minimize default to false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions