百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rails-dev-boost

> 编程语言
开源

加快缓慢的 Rails 开发模式

467 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

加快缓慢的 Rails 开发模式

Fix slow Rails development mode via rails-dev-boost

Make your Rails app 10 times faster in development mode (see FAQ below for more details).

Alternative to Josh Goebel's rails_dev_mode_performance plugin.

Alternative to Robert Pankowecki's active_reload gem.

Branches

If you are using Rails 3 and newer: rails-dev-boost/master branch.

If you are using Rails 2.3: rails-dev-boost/rails-2-3 branch.

If you are using Rails 2.2: rails-dev-boost/rails-2-2 branch.

If you are using Rails 2.1 or Rails 2.0 or anything older: you are out of luck.

Problems

If your app doesn't work with rails-dev-boost:

  • make sure you are not keeping "class-level" references to reloadable constants (see "Known limitations" section below)
  • otherwise please open an issue!

I'm very interested in making the plugin as robust as possible and will work with you on fixing any issues.

Debug mode

There is built-in debug mode in rails-dev-boost that can be enabled by putting this line a Rails initializer file:

RailsDevelopmentBoost.debug! if defined?(RailsDevelopmentBoost)

After restarting your server rails-dev-boost will start to spewing detailed tracing information about its actions into your development.log file.

Background

Why create a similar plugin? Because I couldn't get Josh Goebel's to work in my projects. His attempts to keep templates cached in a way that fails with recent versions of Rails. Also, removing the faulty chunk of code revealed another issue: it stats source files that may not exist, without trying to find their real path beforehand. That would be fixable is the code wasn't such a mess (no offense).

I needed better performance in development mode right away, so here is an alternative implementation.

Usage

Rails 3

Usage through Gemfile:

ruby
group :development do
  gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git'
end

Installing as a plugin:

script/rails plugin install git://github.com/thedarkone/rails-dev-boost

Rails 2.3 and older

script/plugin install git://github.com/thedarkone/rails-dev-boost -r rails-2-3

When the server is started in development mode, the special unloading mechanism takes over.

It can also be used in combination with RailsTestServing for even faster test runs by forcefully enabling it in test mode. To do so, add the following in config/environments/test.rb:

ruby
def config.soft_reload() true end if RailsTestServing.active?

Known limitations

The only code rails-dev-boost is unable to handle are "class-level" reloadable constant inter-references ("reloadable" constants are classes/modules that are automatically reloaded in development mode: models, helpers, controllers etc.).

Class-level reference examples

ruby
# app/models/article.rb
class Article
end

# app/models/blog.rb
class Blog
  ARTICLE_CLASS = Article #  Article
    => Article
    irb(main):002:0> Blog
    => Blog
    irb(main):003:0> Blog.object_id
    => 2182137540
    irb(main):004:0> Article.object_id
    => 2182186060
    irb(main):005:0> Blog::ARTICLE_CLASS.object_id
    => 2182186060
    irb(main):006:0> Blog.all_articles.first.class.object_id
    => 2182186060

Now imagine that we change the `app/models/article.rb` and add a new method:

```ruby
# app/models/article.rb
class Article
  def say_hello
    puts "Hello world!"
  end
end

…

ruby
# app/models/article.rb
class Article < ActiveRecord::Base
end

# app/models/blog.rb
class Blog < ActiveRecord::Base
  def self.all_articles
    @all_articles ||= Article.all
  end
end

can easily be rewritten like this:

ruby
# app/models/article.rb
class Article < ActiveRecord::Base
  def self.all_articles
    @all_articles ||= all
  end
end

# app/models/blog.rb
class Blog < ActiveRecord::Base
  def self.all_articles
    Article.all_articles
  end
end

This way saving arcticle.rb will trigger the reload of @all_articles.

require_dependency

If the code refactor isn't possible, make use of the ActiveSupport's require_dependency:

ruby
#app/models/blog.rb
require_dependency 'article'

class Blog < ActiveRecord::Base
  def self.all_articles
    @all_articles ||= Article.all
  end
  
  def self.authors
    @all_authors ||= begin
      require_dependency 'author' # dynamic require_dependency is also fine
      Author.all
    end
  end
end

Asynchronous mode

By default rails-dev-boost now runs in an "async" mode, watching and unloading modified files in a separate thread. This allows for an even faster development mode because there is no longer a need to do a File.mtime check of all the .rb files at the beginning of the request.

To disable the async mode put the following code in a Rails initializer file (these are found in config/initializers directory):

ruby
RailsDevelopmentBoost.async = false

…

ruby
RailsDevelopmentBoost.reload_routes_on_any_change = true

FAQ

Q: Since the plugin uses its special "unloading mechanism" won't everything break down?

A: Very unlikely... of course there are some edge cases where you might see some breakage (mainly if you're deviating from the Rails 1 file = 1 class conventions or doing some weird requires). This is a 99% solution and the seconds you're wasting waiting for the Rails to spit out a page in the dev mode do add up in the long run.

Q: How big of a boost is it going to give me?

A: It depends on the size of your app (the bigger it is the bigger your boost is going to be). The speed is then approximately equal to that of production env. plus the time it takes to stat all your app's *.rb files (which is surprisingly fast as it is cached by OS). Empty 1 controller 2 views app will become about 4x times faster more complex apps will see huge improvements.

Q: I'm using an older version of Rails than 2.2, will this work for me?

A: Unfortunately you are on your own right now :(.

Q: My Article model does not pick up changes from the articles table.

A: You need to force it to be reloaded (just hit the save button in your editor for article.rb file).

Q: I used require 'article' and the Article model is not being reloaded.

A: You really shouldn't be using require to load your files in the Rails app (if you want them to be automatically reloaded) and let automatic constant loading handle the require for you. You can also use require_dependency 'article', as it goes through the Rails stack.

Q: I'm using JRuby, is it going to work?

A: I haven't tested the plugin with JRuby, but the plugin does use ObjectSpace to do its magic. ObjectSpace is AFAIK disabled by default on JRuby.

FAQ added by thedarkone.

Credits

Written by Roman Le Négrate (contact). Released under the MIT-license: see the LICENSE file.

Issues· 6 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言