0

I have build setup using gulp and I use chokidar for listening for file changes:

var buildWatcher = chokidar.watch(paths, { ignoreInitial: true });

buildWatcher
    .on('add', function(filePath) {
        gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(filePath) + ' add'));
        gulp.start(key + suffix);
    })
    .on('change', function(filePath) {
        gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(filePath) + ' change'));
        gulp.start(key + suffix);
    })
    .on('unlink', function(filePath) {
        gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(filePath) + ' unlink'));
        gulp.start(key + suffix);
    });

I'm struggling with an issue, like a memory leak or sth, namely: every time a file is saved, the watch process is taking more resources (CPU in Task Manager) and as a result whole gulp.start'ed task takes longer. When starting new gulp, initially tasks are running smoothly, CPU usage is low, started tasks take a couple of ms to execute. But saving (even the same file) a few times, and CPU usage raises to 100% for a few seconds.

I tried switching to gulp.watch (3.9):

gulp.watch(paths, function(event) {
    gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(event.path) + ' ' + event.type));
    gulp.start(key + suffix);
}).on('error', function(error) {
    gulpUtil.log(error);
});

and here I don't have this issue. However gulp.watch does not support listening for new files, and this is why I wan't to use chokidar.

Do you know what could be the issue behind chokidar performance issue? How can it be diagnosed?

Thanks

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
dragonfly
  • 17,407
  • 30
  • 110
  • 219

1 Answers1

0

I dont know about the performance of chokidar, but I will suggest you to use gulp-watch.

Notice that you need absoulte path for that.

Check also why gulp.watch doesnt support new/removed files here.

Community
  • 1
  • 1
avcajaraville
  • 9,041
  • 2
  • 28
  • 37
  • I was using gulp-watch initially, but I had the same performance problems, because gulp-watch is using chokidar under the hood. – dragonfly Dec 02 '15 at 11:02
  • I have a very complex set up using gulp-watch and experienced zero performance issues. Weir. Im watching 6 different folders with different watchers... Maybe your problem is somewhere else. – avcajaraville Dec 02 '15 at 11:06
  • Seems that i'm not the only one experiencing it: https://github.com/paulmillr/chokidar/issues/328 – dragonfly Dec 02 '15 at 12:22