From 7367a0bfd073f25b270773276a111363a155a6d2 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 1 Apr 2025 17:07:01 -0700 Subject: [PATCH] fs: improve globSync performance --- lib/internal/fs/glob.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/internal/fs/glob.js b/lib/internal/fs/glob.js index a20ca9d2b26fb5..def75f85e17bb2 100644 --- a/lib/internal/fs/glob.js +++ b/lib/internal/fs/glob.js @@ -331,10 +331,7 @@ class Glob { const fullpath = resolve(this.#root, path); // If path is a directory, add trailing slash and test patterns again. - // TODO(Trott): Would running #isExcluded() first and checking isDirectory() only - // if it matches be more performant in the typical use case? #isExcluded() - // is often ()=>false which is about as optimizable as a function gets. - if (this.#cache.statSync(fullpath).isDirectory() && this.#isExcluded(`${fullpath}/`)) { + if (this.#isExcluded(`${fullpath}/`) && this.#cache.statSync(fullpath).isDirectory()) { return; }