From 58b82f2b7241d93f431452001c4c99cde64a197b Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sat, 5 May 2018 18:21:43 +0100 Subject: [PATCH] fix: increase perf of watching large file count Fixes #1317 Originally a new Set was generated upon every individual file (or dir) watched. This typically doesn't take a long time, but if there's 10,000 files to watch, it's very, very slow. Moving this logic out to the ready event instead, cuts all the processing time of the watch right down. --- lib/monitor/watch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/monitor/watch.js b/lib/monitor/watch.js index 99f0b66b..13b63b7a 100644 --- a/lib/monitor/watch.js +++ b/lib/monitor/watch.js @@ -91,12 +91,12 @@ function watch() { } watchedFiles.push(file); - watchedFiles = Array.from(new Set(watchedFiles)); // ensure no dupes - total = watchedFiles.length; bus.emit('watching', file); debug('watching dir: %s', file); }); watcher.on('ready', function () { + watchedFiles = Array.from(new Set(watchedFiles)); // ensure no dupes + total = watchedFiles.length; watcher.ready = true; resolve(total); debugRoot('watch is complete');