Skip to content

Slow task execution when using gulp.watch with large tasks #285

Closed
@shrink

Description

@shrink

[Edit: added a better example as a comment below]

I have a project with a lot of images, I have a gulp task (images) for processing these images that takes 9 seconds to copy the images to a new folder. I have a gulp task called watch that listens for various changes throughout the project and triggers corresponding tasks:

// run phpunit
gulp.task('tests', function() {
  return gulp.src('./app/tests/*.php')
    .pipe(phpunit('/usr/bin/phpunit'));
});

// move all images to the assets dir
gulp.task('images', function () {
  return gulp.src('app/assets/website/images/**/*')
    .pipe(gulp.dest('public/assets/img'));
});

// watch for changes in files and run corresponding tests
gulp.task('watch', function () {
  gulp.watch('app/**/*.php', ['tests']);
});

I run gulp watch and change app/file.php, the task tests (triggered by the watcher) runs as expected and takes ~1 second to complete.

I then update the watch task to include a watcher for the images directory that triggers the images task:

gulp.task('watch', function () {
  gulp.watch('app/assets/website/images/**/*', ['images']);
  gulp.watch('app/**/*.php', ['tests']);
});

Now I change app/file.php again and this time the task tests (triggered by the watcher) takes 10 seconds to run.

If I run gulp tests it completes in 1 second
If I run gulp watch with only a watcher for tests, when a change is detected tests completes in 1 second
If I run gulp watch with a watcher for images, when a change is detected tests completes in 10 seconds.

Any ideas would could be causing this? Bug? Intentional? PEBCAK?

(note: I have tried this with various different tasks in place of tests, the same behaviour happens if I run a task for compiling less, concatenating javascript etc)

The exact gulpfile.js that has this behaviour is as follows:

var gulp        = require('gulp');
var gutil       = require('gulp-util');
var less        = require('gulp-less');
var autoprefix  = require('gulp-autoprefixer');
var minifycss   = require('gulp-minify-css');
var uglify      = require('gulp-uglify');
var include     = require('gulp-include');
var concat      = require('gulp-concat');
var phpunit     = require('gulp-phpunit');
var fs          = require('fs');

gulp.task('images', function () {
  return gulp.src('app/assets/website/images/**/*')
    .pipe(gulp.dest('public/assets/img'));
});

gulp.task('tests', function() {
  return gulp.src('./app/tests/*.php')
    .pipe(phpunit('/usr/bin/phpunit'));
});
gulp.task('watch', function () {
    gulp.watch('app/assets/website/images/**/*', ['images']);
    gulp.watch('app/**/*.php', ['tests']);
});

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions