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(NODE-3197): revert setImmediate in waitQueue #2802

Merged
merged 2 commits into from
May 12, 2021

Conversation

nbbeeken
Copy link
Contributor

A performance regression was identified in switching the connection pool to using setImmediate instead of process.nextTick for wait queue processing. This patch reverts that change.

NODE-3197

A performance regression was identified in switching the connection
pool to using setImmediate instead of process.nextTick for wait
queue processing. This patch reverts that change.
@nbbeeken nbbeeken requested review from a team, durran, emadum and dariakp and removed request for a team May 10, 2021 19:05
Copy link
Member

@durran durran left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -231,7 +231,7 @@ export class ConnectionPool extends EventEmitter {
}

this[kWaitQueue].push(waitQueueMember);
setImmediate(() => processWaitQueue(this));
process.nextTick(() => processWaitQueue(this));

Choose a reason for hiding this comment

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

process.nextTick() forwards the second and subsequent arguments to the callback function. It permits to avoid creating an unnecessary closure and improves performance further. It's a very popular pattern across the Node.js core codebase (https://github.com/nodejs/node/search?p=1&q=process.nextTick+path%3Alib%2F).

Suggested change
process.nextTick(() => processWaitQueue(this));
process.nextTick(processWaitQueue, this);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking the time to suggest this, I agree we can drop the closure

@nbbeeken nbbeeken merged commit 6c0dfef into 4.0 May 12, 2021
@nbbeeken nbbeeken deleted the NODE-3197/waitQueueEventLoop branch May 12, 2021 17:50
ljhaywar pushed a commit that referenced this pull request Nov 9, 2021
A performance regression was identified in switching the connection
pool to using setImmediate instead of process.nextTick for wait
queue processing. This patch reverts that change.
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.

5 participants