From a10531a44d5bb3a3deb84acd4317fcb2059551b6 Mon Sep 17 00:00:00 2001 From: Gary Borton Date: Tue, 16 Jul 2024 18:42:10 -0700 Subject: [PATCH] Avoid creating a new array inside doResolve. --- lib/Resolver.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Resolver.js b/lib/Resolver.js index ba1dba9..fdb73dc 100644 --- a/lib/Resolver.js +++ b/lib/Resolver.js @@ -692,7 +692,11 @@ class Resolver { } newStack.add(stackEntry); } else { - newStack = new Set([stackEntry]); + // creating a set with new Set([item]) + // allocates a new array that has to be garbage collected + // this is an EXTREMELY hot path, so let's avoid it + newStack = new Set(); + newStack.add(stackEntry); } this.hooks.resolveStep.call(hook, request);