-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/cmap/connection_pool.ts
Outdated
@@ -231,7 +231,7 @@ export class ConnectionPool extends EventEmitter { | |||
} | |||
|
|||
this[kWaitQueue].push(waitQueueMember); | |||
setImmediate(() => processWaitQueue(this)); | |||
process.nextTick(() => processWaitQueue(this)); |
There was a problem hiding this comment.
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).
process.nextTick(() => processWaitQueue(this)); | |
process.nextTick(processWaitQueue, this); |
There was a problem hiding this comment.
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
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