From 72e12ff0ed5940d0435cf680cd7cd5452f5a9e17 Mon Sep 17 00:00:00 2001 From: Mark Molinaro Date: Wed, 17 Nov 2021 11:40:32 -0800 Subject: [PATCH] perf: correctly split timestamp by file/dependency and only call getTimeInfoEntries once --- lib/node/NodeWatchFileSystem.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/node/NodeWatchFileSystem.js b/lib/node/NodeWatchFileSystem.js index 67ef918b8a3..6119daf9e46 100644 --- a/lib/node/NodeWatchFileSystem.js +++ b/lib/node/NodeWatchFileSystem.js @@ -68,6 +68,8 @@ class NodeWatchFileSystem { if (callbackUndelayed) { this.watcher.once("change", callbackUndelayed); } + + let fileMap, directoryMap; this.watcher.once("aggregated", (changes, removals) => { if (this.inputFileSystem && this.inputFileSystem.purge) { const fs = this.inputFileSystem; @@ -78,8 +80,10 @@ class NodeWatchFileSystem { fs.purge(item); } } - const times = this.watcher.getTimeInfoEntries(); - callback(null, times, times, changes, removals); + fileMap = new Map(); + directoryMap = new Map(); + this.watcher.getTimeInfoEntries(fileMap, directoryMap); + callback(null, fileMap, directoryMap, changes, removals); }); this.watcher.watch({ files, directories, missing, startTime }); @@ -120,18 +124,18 @@ class NodeWatchFileSystem { return items; }, getFileTimeInfoEntries: () => { + if (fileMap) return fileMap; if (this.watcher) { return this.watcher.getTimeInfoEntries(); - } else { - return new Map(); } + return new Map(); }, getContextTimeInfoEntries: () => { + if (directoryMap) return directoryMap; if (this.watcher) { return this.watcher.getTimeInfoEntries(); - } else { - return new Map(); } + return new Map(); } }; }