From 86295a890b3fe09b603acfff174ca1592822a180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Tue, 17 Oct 2023 22:30:29 -0300 Subject: [PATCH 1/3] lib: avoid memory allocation on nodeprecation flag --- lib/internal/modules/esm/resolve.js | 9 +++++++++ lib/internal/process/warning.js | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 58e7df07ca5275..06a34c11254a2f 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -75,6 +75,9 @@ const emittedPackageWarnings = new SafeSet(); * @param {string} base - The URL of the module that imported the package. */ function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) { + if (process.noDeprecation) { + return; + } const pjsonPath = fileURLToPath(pjsonUrl); if (emittedPackageWarnings.has(pjsonPath + '|' + match)) { return; } emittedPackageWarnings.add(pjsonPath + '|' + match); @@ -101,6 +104,9 @@ const doubleSlashRegEx = /[/\\][/\\]/; * @param {boolean} isTarget - Whether the target is a module. */ function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, internal, base, isTarget) { + if (process.noDeprecation) { + return; + } const pjsonPath = fileURLToPath(pjsonUrl); const double = RegExpPrototypeExec(doubleSlashRegEx, isTarget ? target : request) !== null; process.emitWarning( @@ -123,6 +129,9 @@ function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, interna * @param {string} [main] - The "main" field from the package.json file. */ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { + if (process.noDeprecation) { + return; + } const format = defaultGetFormatWithoutErrors(url); if (format !== 'module') { return; } const path = fileURLToPath(url); diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 3ce00004dab476..5f8c502f74e8d4 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -127,6 +127,11 @@ function onWarning(warning) { // process.emitWarning(str[, type[, code]][, ctor]) // process.emitWarning(str[, options]) function emitWarning(warning, type, code, ctor) { + // fast path to avoid memory allocation, + // this doesn't eliminate the other if a few lines below + if (type === 'DeprecationWarning' && process.noDeprecation) { + return; + } let detail; if (type !== null && typeof type === 'object' && !ArrayIsArray(type)) { ctor = type.ctor; From 72f1eb2cdce3c04bc718caaa5f2041326d4f3df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Wed, 18 Oct 2023 13:04:52 -0300 Subject: [PATCH 2/3] fixup! lib: avoid memory allocation on nodeprecation flag --- lib/internal/process/warning.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 5f8c502f74e8d4..bf03944759bbce 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -127,7 +127,7 @@ function onWarning(warning) { // process.emitWarning(str[, type[, code]][, ctor]) // process.emitWarning(str[, options]) function emitWarning(warning, type, code, ctor) { - // fast path to avoid memory allocation, + // Fast path to avoid memory allocation, // this doesn't eliminate the other if a few lines below if (type === 'DeprecationWarning' && process.noDeprecation) { return; From 21e87a9f0909fc801af6185200edb61545838faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Fri, 27 Oct 2023 21:42:25 -0300 Subject: [PATCH 3/3] fixup! lib: avoid memory allocation on nodeprecation flag --- lib/internal/process/warning.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index bf03944759bbce..4aa86b9df58a87 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -129,7 +129,7 @@ function onWarning(warning) { function emitWarning(warning, type, code, ctor) { // Fast path to avoid memory allocation, // this doesn't eliminate the other if a few lines below - if (type === 'DeprecationWarning' && process.noDeprecation) { + if (process.noDeprecation && type === 'DeprecationWarning') { return; } let detail;