Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I doing something wrong with the asset pipeline?

Since "upgrading" to Rails 3.1 my app is really slow in development mode

(> 30 per request)

I have a lot of images and it seems most of this time-delay is the asset pipeline processing each GET request for each image.

Don't have this problem in Staging or Production mode as the assets are cached etc.

Is there something I haven't been told or is this how we're expected to work now?

like image 667
bodacious Avatar asked Jun 22 '11 09:06

bodacious


People also ask

How does Rails asset pipeline work?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.

How do you Precompile an asset?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What does rake assets Clean do?

Two cleanup tasks: rake assets:clean is now a safe cleanup that only removes older assets that are no longer used, while rake assets:clobber nukes the entire public/assets directory. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.


1 Answers

Requests can be slow if you have gems or portions of your app that load code at the start of each request - or that merely reference portions of your app, causing much of it to be loaded. For most of these, the autoloader is the prime cause of request delay.

The rails auto-reloader deletes any autoloadable classes/modules/etc at the start of each request, and can cause significant delays at the beginning of each request as Rails reloads all the source files it needs.

You might want to try playing with https://github.com/wavii/rails-dev-tweaks, which gives you granular control over which requests cause the auto-reloader to kick in. This really isn't a fix of the root cause (something is doing extra work at the start of every request that it probably doesn't need to be doing) - but it certainly mitigates most such issues.

like image 198
Nevir Avatar answered Sep 19 '22 21:09

Nevir