orourkedd
orourkedd

Reputation: 6421

Rails 4 asset pipline slow

I have read dozens of posts all over the internet about this but mostly for Rails 3.

For some reason, it takes 35 seconds to load a page with a total of 34 assets in development.

I have done the following:

  1. Set config.assets.debug = false in development.rb, but this only cuts it down to 30 seconds,
  2. reloaded the page multiple times, but each load is just as slow,
  3. precompiled the assets manually (although this seems to only applies in production),
  4. looked for something like rails-dev-boost (https://github.com/thedarkone/rails-dev-boost) but cannot find anything for rails 4.

I'm developing on an ubuntu box using vagrant (https://github.com/rails/rails-dev-box). The host machine is the fastest, new MacBook Pro.

I'm almost going to throw out the asset pipeline altogether and compile the assets myself. I cannot wait 35 seconds every time I need to reload the page.

Any help on this is appreciated.

Page load details

development.rb:

MyProject::Application.configure do

  config.cache_classes = false

  config.eager_load = false

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = false

  config.active_support.deprecation = :log

  config.active_record.migration_error = :page_load

  config.assets.debug = false

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end

Edit

I think the issue is the VM. I installed ruby on my Mac using homebrew and ran the same project with the exact configuration and it loads in under 1 second. I'm not sure what the problem is.

Upvotes: 3

Views: 1008

Answers (2)

aarons22
aarons22

Reputation: 147

The issue is probably with your shared_folder on Vagrant box, which can be fixed by using rsync:

  1. Install rync on your mac: brew install rsync
  2. In your Vagrant file, add type: "rsync" to your synced_folder: config.vm.synced_folder "[path to host folder]", "[path to guest folder]", type: "rsync"

I was experiencing 20-25 second page load times, and once I added rsync, my pages were loading in under a second. Since the shared_folder by default is only pointing to your code, it essentially has to load those files to the VM each time the page loads.

Upvotes: 3

okliv
okliv

Reputation: 3959

adding gem 'rack-mini-profiler' or less-easy-to-use gem 'ruby-prof' can help to find what renders slow

i have around fifty heavy js|css files and it renders pretty fast in development environment, so it is very unlikely that problem core in assets pipeline itself

Upvotes: 0

Related Questions