Measure it

First you have to find out what is slow before you can fix it. capistrano-measure is a project that can help you do that.

Your output will be something like this:

I, [2017-04-27T11:40:30.585704 #11159]  INFO -- : ============================================================
I, [2017-04-27T11:40:30.586152 #11159]  INFO -- :   Performance Report
I, [2017-04-27T11:40:30.586189 #11159]  INFO -- : ============================================================
I, [2017-04-27T11:40:30.586237 #11159]  INFO -- : production
I, [2017-04-27T11:40:30.586413 #11159]  INFO -- : ..load:defaults 0s
I, [2017-04-27T11:40:30.586645 #11159]  INFO -- : ..rvm:hook 1s
I, [2017-04-27T11:40:30.586847 #11159]  INFO -- : ..rvm:check 1s
I, [2017-04-27T11:40:30.586978 #11159]  INFO -- : ..bundler:map_bins 0s
I, [2017-04-27T11:40:30.587122 #11159]  INFO -- : ..deploy:set_rails_env 0s
I, [2017-04-27T11:40:30.587530 #11159]  INFO -- : ..avvo:map_bins 0s
I, [2017-04-27T11:40:30.587971 #11159]  INFO -- : production 3s
I, [2017-04-27T11:40:30.588021 #11159]  INFO -- : deploy
I, [2017-04-27T11:40:30.588063 #11159]  INFO -- : ..deploy:starting
I, [2017-04-27T11:40:30.588314 #11159]  INFO -- : ....deploy:check
I, [2017-04-27T11:40:30.588938 #11159]  INFO -- : ......deploy:check:directories 0s
I, [2017-04-27T11:40:30.589179 #11159]  INFO -- : ......deploy:check:linked_dirs 0s
I, [2017-04-27T11:40:30.589410 #11159]  INFO -- : ......deploy:check:make_linked_dirs 0s
I, [2017-04-27T11:40:30.596548 #11159]  INFO -- : ......deploy:check:linked_files 0s
I, [2017-04-27T11:40:30.597144 #11159]  INFO -- : ....deploy:check 0s
I, [2017-04-27T11:40:30.597678 #11159]  INFO -- : ....deploy:set_previous_revision 0s
I, [2017-04-27T11:40:30.597982 #11159]  INFO -- : ..deploy:starting 0s
I, [2017-04-27T11:40:30.598162 #11159]  INFO -- : ..deploy:started 0s
I, [2017-04-27T11:40:30.598318 #11159]  INFO -- : ..deploy:new_release_path 0s
I, [2017-04-27T11:40:30.598369 #11159]  INFO -- : ..deploy:updating
I, [2017-04-27T11:40:30.598660 #11159]  INFO -- : ....deploy:set_current_revision 0s
I, [2017-04-27T11:40:30.598710 #11159]  INFO -- : ....deploy:symlink:shared
I, [2017-04-27T11:40:30.598853 #11159]  INFO -- : ......deploy:symlink:linked_files 0s
I, [2017-04-27T11:40:30.598994 #11159]  INFO -- : ......deploy:symlink:linked_dirs 1s
I, [2017-04-27T11:40:30.599133 #11159]  INFO -- : ....deploy:symlink:shared 1s
I, [2017-04-27T11:40:30.599297 #11159]  INFO -- : ..deploy:updating 10s
I, [2017-04-27T11:40:30.599526 #11159]  INFO -- : ..bundler:install 11s
I, [2017-04-27T11:40:30.599583 #11159]  INFO -- : ..deploy:updated
I, [2017-04-27T11:40:30.599615 #11159]  INFO -- : ....deploy:compile_assets
I, [2017-04-27T11:40:30.599768 #11159]  INFO -- : ......deploy:assets:precompile 1s
I, [2017-04-27T11:40:30.599914 #11159]  INFO -- : ......deploy:assets:backup_manifest 0s
I, [2017-04-27T11:40:30.600134 #11159]  INFO -- : ....deploy:compile_assets 2s
I, [2017-04-27T11:40:30.600464 #11159]  INFO -- : ....deploy:normalize_assets 0s
I, [2017-04-27T11:40:30.600650 #11159]  INFO -- : ....deploy:migrate 13s
I, [2017-04-27T11:40:30.600811 #11159]  INFO -- : ..deploy:updated 16s
I, [2017-04-27T11:40:30.600849 #11159]  INFO -- : ..deploy:publishing
I, [2017-04-27T11:40:30.600986 #11159]  INFO -- : ....deploy:symlink:release 0s
I, [2017-04-27T11:40:30.601213 #11159]  INFO -- : ..deploy:publishing 0s
I, [2017-04-27T11:40:30.601337 #11159]  INFO -- : ..deploy:restart 6s
I, [2017-04-27T11:40:30.601472 #11159]  INFO -- : ..deploy:published 0s
I, [2017-04-27T11:40:30.601510 #11159]  INFO -- : ..deploy:finishing
I, [2017-04-27T11:40:30.601627 #11159]  INFO -- : ....deploy:cleanup 0s
I, [2017-04-27T11:40:30.601749 #11159]  INFO -- : ....honeybadger:env 0s
I, [2017-04-27T11:40:30.601916 #11159]  INFO -- : ....honeybadger:deploy 4s
I, [2017-04-27T11:40:30.602019 #11159]  INFO -- : ..deploy:finishing 5s
I, [2017-04-27T11:40:30.602055 #11159]  INFO -- : ..deploy:finished
I, [2017-04-27T11:40:30.602157 #11159]  INFO -- : ....deploy:log_revision 0s
I, [2017-04-27T11:40:30.602324 #11159]  INFO -- : ..deploy:finished 0s
I, [2017-04-27T11:40:30.602425 #11159]  INFO -- : deploy 52s
I, [2017-04-27T11:40:30.602456 #11159]  INFO -- : ============================================================

Ok, it was probably your assets. Now what?

Skip them a lot of the time!

Tons of shipments don't even have asset changes, so why bother compiling again when we can reuse the previously compiled assets? There's a gem for that! capistrano-faster-assets.

At Avvo this saves about 15 minutes of deploy time for both staging and production deployments, for a total savings of 30 minutes per no-assets-changed shipment.

Remove some?

We took out all of the images in our biggest project and moved them to S3. They are easier to update there anyways (doesn't require a developer), and this sped up asset compilation by several minutes.

Speed them up!

Sometimes the bruteforce option is the best option. If it's been a while since you've dug into your asset pipeline, you might have missed two big improvements to asset compilation: SassC and MiniRacer.

Better V8 with MiniRacer

MiniRacer is an alternative to therubyracer, and does more or less the same thing: it connects to V8 to run JavaScript build tools. I've heard MiniRacer can help speed up JavaScript minification, but we didn't see a huge improvement in our own performance testing.

What we did notice, though, is that MiniRacer is less tied to a specific version of V8. With therubyracer, we had a tough time keeping our V8 libraries in sync in each of our environments and across different operating systems. It was the gem that failed to install most frequently.

MiniRacer tries to always support the newest version of V8, which is much easier to find and install. And the change was easy:

-  gem 'therubyracer'
-  gem 'libv8', '3.16.14.19'
+  gem 'mini_racer'

Faster Sass with SassC

Sass was originally written in Ruby. To speed it up, a group of people wrote a C++ implementation of Sass, called libsass. Libsass needs some help before you can use it in your app, though, and that's where SassC can help you out.

SassC is a more-or-less drop-in replacement for Sass:

-gem 'sass-rails', '5.0.3'
+gem 'sassc-rails', '~> 1.3.0'

After making that change, we saw a 230% speedup in asset compilation time. Pretty great for less than an hour's worth of work.