An inquiry regarding Promises vs Callbacks and performance impact within the event loop

1 day ago 1
ARTICLE AD BOX

so I have been diving into NodeJS's internals and specifically in the event loop and how it handles different phases and whilst I was reading and wrapping my head around things I had a thought about how promises add an extra layer of performance overhead even though I think it is really really small. So, from what I understand during the poll phase callbacks are queued and whatever you're doing is now accessible to you whether its an I/O operation, network or whatever.

func((err, data) => { if (err) { throw error; } else { doSomething(data); } })

But after the introduction of the Promises API, we can now use .then()/catch(), or async/await. From my understanding when resolving, a task is enqueued within the micro tasks queue, adding an additional performance overhead since now we Poll -> Microtasks Drain instead of just polling. So my question is does this really introduce an additional overhead, and if so how much does performance get impacted? Would appreciate any help or clarification I could get.

Read Entire Article