You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#739 introduced Clone for Channel (formerly EventQueue) that shares a backing Node-API threadsafe function.
Additionally, the cx.channel() (formerly cx.queue()) method has been changed to return a clone of a globally shared Channel.
In order to drop a referenced clone of a Channel, it must send an event back to be processed on the event loop to perform the unref. In most scenarios this is very fast because of an optimization in Node that will process multiple events within a single tick. nodejs/node#38506
This will result in better performance on recent Node versions with common usage patterns; however, there is one scenario where performance degradation is extreme (as much as 3x).
N-API Version 6+ (lower versions do not have a shared queue)
Node version less than 14.7.0 or 16.2.0
cx.channel() is used to create a Channel that is used once and dropped
Little to no concurrency
In this pathological example, the number of ticks required to process events are doubled.
Proposals
unref within event optimization
In many cases, the event sent to unref can be omitted completely when we know it is not possible for there to be other pending events that were sent on a referenced channel.
The advantage is that this will cover nearly all use cases. The issue is that it significantly increases the complexity of Channel. An additional counter will be required (either via an Arc on the inner state or a pending messages counter) to tell when it is safe to unref within that event. It is important not to unref when there are pending messages because it allows Node to exit immediately, even if it shouldn't.
Runtime version detection
Neon may check the currently running Node version and not give a shared Channel from cx.channel() if the Node version does not contain the multiple-events per tick optimization.
The advantage of this is that it's much simpler. The disadvantage is that it makes the operation of Neon less predictable.
The text was updated successfully, but these errors were encountered:
Description
#739 introduced
Clone
forChannel
(formerlyEventQueue
) that shares a backing Node-API threadsafe function.Additionally, the
cx.channel()
(formerlycx.queue()
) method has been changed to return a clone of a globally sharedChannel
.In order to drop a referenced clone of a
Channel
, it must send an event back to be processed on the event loop to perform theunref
. In most scenarios this is very fast because of an optimization in Node that will process multiple events within a single tick. nodejs/node#38506This will result in better performance on recent Node versions with common usage patterns; however, there is one scenario where performance degradation is extreme (as much as 3x).
14.7.0
or16.2.0
cx.channel()
is used to create aChannel
that is used once and droppedIn this pathological example, the number of ticks required to process events are doubled.
Proposals
unref
within event optimizationIn many cases, the event sent to
unref
can be omitted completely when we know it is not possible for there to be other pending events that were sent on a referenced channel.The advantage is that this will cover nearly all use cases. The issue is that it significantly increases the complexity of
Channel
. An additional counter will be required (either via anArc
on the inner state or a pending messages counter) to tell when it is safe tounref
within that event. It is important not tounref
when there are pending messages because it allows Node to exit immediately, even if it shouldn't.Runtime version detection
Neon may check the currently running Node version and not give a shared
Channel
fromcx.channel()
if the Node version does not contain the multiple-events per tick optimization.The advantage of this is that it's much simpler. The disadvantage is that it makes the operation of Neon less predictable.
The text was updated successfully, but these errors were encountered: