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: make a few micro-optimizations to help speed up findOne() #15022

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

vkarpov15
Copy link
Collaborator

Re: #14906

Summary

Some small improvements that maybe give us an extra 1-2% on performance. Not huge, but a step in the right direction. I'm still debugging to see where we can find some extra perf.

Examples

@vkarpov15 vkarpov15 added this to the 8.8.1 milestone Nov 6, 2024
lib/query.js Outdated
@@ -2291,9 +2293,9 @@ Query.prototype.mongooseOptions = function(v) {

Query.prototype._castConditions = function() {
let sanitizeFilterOpt = undefined;
if (this.model != null && utils.hasUserDefinedProperty(this.model.db.options, 'sanitizeFilter')) {
if (this.model != null && this.model.db.options?.sanitizeFilter != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can also be shortened to:

Suggested change
if (this.model != null && this.model.db.options?.sanitizeFilter != null) {
if (this.model?.db.options?.sanitizeFilter != null) {

lib/query.js Outdated
sanitizeFilterOpt = this.model.db.options.sanitizeFilter;
} else if (this.model != null && utils.hasUserDefinedProperty(this.model.base.options, 'sanitizeFilter')) {
} else if (this.model != null && this.model.base.options?.sanitizeFilter != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Suggested change
} else if (this.model != null && this.model.base.options?.sanitizeFilter != null) {
} else if (this.model?.base.options?.sanitizeFilter != null) {

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

A couple of minor suggestions, otherwise LGTM.

@vkarpov15 vkarpov15 merged commit 537032d into master Nov 7, 2024
56 of 58 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-14906 branch November 7, 2024 14:57
vkarpov15 added a commit that referenced this pull request Dec 16, 2024
vkarpov15 added a commit that referenced this pull request Dec 17, 2024
refactor(query): simplify CastError check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants