Search code examples
rubyruby-on-rails-3guard

Why guard uses cpu almost 100%?


I've started to use guard to monitor my testing changes, but is using so much cpu (between 80%~95% of CPU). I'm using it in conjuction with all these guard gems

gem "guard-rspec"
gem 'guard-livereload'
gem 'guard-rails-assets'
gem 'guard-bundler'

I though maybe is just my laptop, but other coworkers use them in their new laptops(newer than mine) and is using about 60~70% of cpu all the time. I've tried to just run guard without all the other gems but the result is the same.

Is there a way to configure it and minimize their cpu usage?


Solution

  • Yes, you can tweak Guard to be more efficient by

    1. Enable OS file system notifications as described in efficient filesystem handling.
    2. Ignore directories that are not of interest with the ignore DSL method.
    3. Filter changes to file types of interest with the filter DSL method.

    On my 2012 27" iMac watching a large Rails project with many active Guard plugins, the Guard process takes 0.01% of CPU time when listening to file changes.