diff --git a/lib/dgram.js b/lib/dgram.js index 0a72834873e8bd..f3454ffc0702c4 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -35,7 +35,6 @@ const { ERR_SOCKET_DGRAM_NOT_RUNNING } = errors.codes; const { Buffer } = require('buffer'); -const dns = require('dns'); const util = require('util'); const { isUint8Array } = require('internal/util/types'); const EventEmitter = require('events'); @@ -47,6 +46,9 @@ const { UV_UDP_REUSEADDR } = process.binding('constants').os; const { UDP, SendWrap } = process.binding('udp_wrap'); +// Lazy load for startup performance. +let dns; + const BIND_STATE_UNBOUND = 0; const BIND_STATE_BINDING = 1; const BIND_STATE_BOUND = 2; @@ -72,9 +74,10 @@ function lookup6(lookup, address, callback) { function newHandle(type, lookup) { - if (lookup === undefined) + if (lookup === undefined) { + if (dns === undefined) dns = require('dns'); lookup = dns.lookup; - else if (typeof lookup !== 'function') + } else if (typeof lookup !== 'function') throw new ERR_INVALID_ARG_TYPE('lookup', 'Function', lookup); if (type === 'udp4') {