Replace directory_watcher with listen. #1589

Merged
merged 4 commits into from Oct 24, 2013

Projects

None yet

4 participants

@dchest
Contributor
dchest commented Sep 30, 2013

Directory_watcher consumed ~25% CPU on big Jekyll projects (depending on
the number of watched files), since it polled for changes every second.

Listen is easier on CPU, as it uses directory change notifications
provided by OS (currently OS X and Linux), falling back to polling when
they are not available.

@dchest dchest Replace directory_watcher with listen.
Directory_watcher consumed ~25% CPU on big Jekyll projects (depending on
the number of watched files), since it polled for changes every second.

Listen is easier on CPU, as it uses directory change notifications
provided by OS (currently OS X and Linux), falling back to polling when
they are not available.
8fe25a6
@parkr parkr commented on an outdated diff Sep 30, 2013
lib/jekyll/commands/build.rb
@@ -31,25 +31,24 @@ def self.build(site, options)
#
# Returns nothing.
def self.watch(site, options)
- require 'directory_watcher'
+ require 'listen'
+ require 'pathname'
@parkr
parkr Sep 30, 2013 Member

pathname should already be required. If not, please add it to lib/jekyll.rb

@parkr parkr and 1 other commented on an outdated diff Sep 30, 2013
lib/jekyll/commands/build.rb
source = options['source']
- destination = options['destination']
+ destination = Pathname.new(options['destination'])
+ .relative_path_from(Pathname.new(source))
@parkr
parkr Sep 30, 2013 Member

It's not always a relative path from the source. It's often an absolute path. Will it still register as this?

@dchest
dchest Sep 30, 2013 Contributor

If it's outside of the source, listener won't be trigger by its change.
However, you're correct -- it throws an ArgumentError if destination doesn't share prefix with source. Fixing.

@parkr
Member
parkr commented Sep 30, 2013

I like it. 👍

@mattr-?

@parkr
Member
parkr commented Sep 30, 2013

Is this compatible with Windows at all? Or is it just that Windows will need to use polling?

@dchest
Contributor
dchest commented Sep 30, 2013

@parkr Windows will use polling.

https://github.com/guard/listen/tree/v1.3#on-windows gives instructions on how to enable "wdm", but I'll leave it to Windows programmers to figure out how to integrate it.

@dchest

I went with catching exception, which is ugly, but works. Probably we can just chop source from destination...

Here's what listener does with paths: https://github.com/guard/listen/blob/v1.3/lib/listen/directory_record.rb#L192

@parkr
Member
parkr commented Oct 18, 2013

I'm in love with this PR. @mattr- – good for v1.3?

@mattr- mattr- added a commit that referenced this pull request Oct 24, 2013
@mattr- mattr- Update history to reflect merge of #1589 2c11a6e
@mattr- mattr- merged commit 12ba0a5 into jekyll:master Oct 24, 2013
@maul-esel
Contributor

Travis errors since this was merged because

Gem::InstallError: listen requires Ruby version >= 1.9.3.
An error occurred while installing listen (2.1.1), and Bundler cannot continue.

@mattr-
Member
mattr- commented Oct 27, 2013

Yup. Working on fixing this now.

@dchest dchest referenced this pull request Oct 27, 2013
@mattr- mattr- Downgrade Listen to 1.3.x
This is so that we can be Ruby 1.8.x compatible.
71d4319
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment