diff --git a/benchmark/es/spread-assign.js b/benchmark/es/spread-assign.js index 211979c710baf3..f0dcd56bb606b1 100644 --- a/benchmark/es/spread-assign.js +++ b/benchmark/es/spread-assign.js @@ -1,9 +1,10 @@ 'use strict'; const common = require('../common.js'); +const util = require('util'); const bench = common.createBenchmark(main, { - method: ['spread', 'assign'], + method: ['spread', 'assign', '_extend'], count: [5, 10, 20], n: [1e6], }); @@ -17,6 +18,12 @@ function main({ n, context, count, rest, method }) { let obj; switch (method) { + case '_extend': + bench.start(); + for (let i = 0; i < n; i++) + obj = util._extend({}, src); + bench.end(n); + break; case 'assign': bench.start(); for (let i = 0; i < n; i++) diff --git a/benchmark/misc/util-extend-vs-object-assign.js b/benchmark/misc/util-extend-vs-object-assign.js new file mode 100644 index 00000000000000..e2ac0a5417e489 --- /dev/null +++ b/benchmark/misc/util-extend-vs-object-assign.js @@ -0,0 +1,30 @@ +'use strict'; + +const common = require('../common.js'); +const util = require('util'); + +const bench = common.createBenchmark(main, { + type: ['extend', 'assign'], + n: [10e4], +}); + +function main({ n, type }) { + let fn; + if (type === 'extend') { + fn = util._extend; + } else if (type === 'assign') { + fn = Object.assign; + } + + // Force-optimize the method to test so that the benchmark doesn't + // get disrupted by the optimizer kicking in halfway through. + for (let i = 0; i < type.length * 10; i += 1) + fn({}, process.env); + + const obj = new Proxy({}, { set: function(a, b, c) { return true; } }); + + bench.start(); + for (let j = 0; j < n; j += 1) + fn(obj, process.env); + bench.end(n); +} diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 999c8823b4e59b..8a9f8ade180b8e 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -1408,9 +1408,6 @@ requirements and complexity of your application. -Type: End-of-Life +Type: Runtime -The `util._extend()` API has been removed because it's an unmaintained +The [`util._extend()`][] API is deprecated because it's an unmaintained legacy API that was exposed to user land by accident. Please use `target = Object.assign(target, source)` instead. @@ -3836,6 +3833,7 @@ and [`crypto.setEngine()`][] all depend on this functionality from OpenSSL. [`url.format()`]: url.md#urlformaturlobject [`url.parse()`]: url.md#urlparseurlstring-parsequerystring-slashesdenotehost [`url.resolve()`]: url.md#urlresolvefrom-to +[`util._extend()`]: util.md#util_extendtarget-source [`util.getSystemErrorName()`]: util.md#utilgetsystemerrornameerr [`util.inspect()`]: util.md#utilinspectobject-options [`util.inspect.custom`]: util.md#utilinspectcustom diff --git a/doc/api/util.md b/doc/api/util.md index 776b54a5a2f51d..f9da8d3bd97d58 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -2923,6 +2923,24 @@ util.types.isWeakSet(new WeakSet()); // Returns true The following APIs are deprecated and should no longer be used. Existing applications and modules should be updated to find alternative approaches. +### `util._extend(target, source)` + + + +> Stability: 0 - Deprecated: Use [`Object.assign()`][] instead. + +* `target` {Object} +* `source` {Object} + +The `util._extend()` method was never intended to be used outside of internal +Node.js modules. The community found and used it anyway. + +It is deprecated and should not be used in new code. JavaScript comes with very +similar built-in functionality through [`Object.assign()`][]. + ### `util.isArray(object)`