From afdc3d0d187e4e3a336937df17a4c90092405e2a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 2 Oct 2019 23:26:51 +0200 Subject: dgram: use `uv_udp_try_send()` This improves dgram performance by avoiding unnecessary async operations. One issue with this commit is that it seems hard to actually create conditions under which the fallback path to the async case is actually taken, for all supported OS, so an internal CLI option is used for testing that path. Another caveat is that the lack of an async operation means that there are slight timing differences (essentially `nextTick()` rather than `setImmediate()` for the send callback). PR-URL: https://github.com/nodejs/node/pull/29832 Reviewed-By: David Carlier Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- lib/dgram.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/dgram.js') diff --git a/lib/dgram.js b/lib/dgram.js index 923463cc2e..cc61d4d274 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -666,6 +666,14 @@ function doSend(ex, self, ip, list, address, port, callback) { else err = state.handle.send(req, list, list.length, !!callback); + if (err >= 1) { + // Synchronous finish. The return code is msg_length + 1 so that we can + // distinguish between synchronous success and asynchronous success. + if (callback) + process.nextTick(callback, null, err - 1); + return; + } + if (err && callback) { // Don't emit as error, dgram_legacy.js compatibility const ex = exceptionWithHostPort(err, 'send', address, port); -- cgit v1.2.3