Reduce rails startup costs (time/memory)
Currently rails takes **11 seconds** and **217MB** of memory to start, which we could probably improve on. I've used [derailed_benchmarks](https://github.com/schneems/derailed_benchmarks) to profile startup memory, and [bumbler](https://github.com/nevir/Bumbler) to profile startup time. ## How? Determine if any offending gems are unnecessarily using resources. The worst of these is [linguist](https://github.com/github/linguist) which adds **2s** to the startup time, and **89MB** to startup memory. Updating to v5.0.6 of that gem did not improve memory usage. While some gems will be using memory to make things more efficient later, this isn't always the case and the [mail gem was able to reduce its memory usage significantly after profiling](http://www.schneems.com/2014/11/07/i-ram-what-i-ram.html). ## Why? Developer productivity and application performance. Workarounds like using spring or the web interface to view routes are useful, but can't always be used. ## Profiling All profiling done on GitLab CE, in development mode. ### Initializer timings ``` gitlab|master±?» bumbler --initializers Slow requires: 118.86 active_record.initialize_database 150.29 ./config/initializers/gollum.rb 220.61 ./config/initializers/additional_headers_interceptor.rb 251.04 ./config/initializers/8_metrics.rb 370.01 :finisher_hook 835.28 :load_config_initializers 1620.04 :set_routes_reloader_hook ``` ### Bundler require timings ``` gitlab|master ±?» bumbler [########### ] (140/189) gitaly ( 60.08ms) Slow requires: 100.40 chronic 100.58 charlock_holmes 102.43 thin 108.97 wikicloth 113.23 oauth2 118.10 doorkeeper 119.57 web-console 125.84 rspec_profiling 130.24 factory_girl_rails 132.97 capybara 137.92 omniauth-ldap 141.70 octokit 145.54 kubeclient 168.10 fuubar 175.18 browser 178.67 omniauth-auth0 183.43 rqrcode-rails3 205.78 sentry-raven 207.45 spinach-rails 220.73 virtus 229.78 nokogiri 238.21 rouge 246.48 attr_encrypted 259.22 omniauth-saml 274.70 loofah 293.85 devise-two-factor 309.10 ffaker 320.83 devise 351.82 carrierwave 397.80 hamlit 401.44 grape 425.12 gon 528.43 sprockets 549.85 sass-rails 631.13 pry-byebug 872.17 rails 2086.43 linguist ``` ### Memory usage ``` gitlab|master ±?» CUT_OFF=4 bundle exec derailed bundle:mem TOP: 217.5156 MiB linguist: 89.1602 MiB linguist/language: 77.9336 MiB (Also required by: linguist/lazy_blob) linguist/blob_helper: 10.6797 MiB (Also required by: linguist/file_blob, linguist/blob, and 2 others) mime/types: 9.5781 MiB (Also required by: carrierwave/sanitized_file, /Users/jedwardsjones/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rest-client-2.0.0/lib/restclient/request) rails/all: 20.8984 MiB sprockets/railtie: 13.5234 MiB (Also required by: sass/rails/railtie) sprockets/rails/context: 9.582 MiB action_view/helpers: 9.5195 MiB (Also required by: action_view/base) action_view/helpers/form_helper: 7.1094 MiB (Also required by: action_view/helpers/form_options_helper) action_view/helpers/form_tag_helper: 6.5898 MiB action_view/helpers/text_helper: 6.0859 MiB action_view/helpers/sanitize_helper: 5.9023 MiB rails-html-sanitizer: 5.8281 MiB loofah: 5.5586 MiB (Also required by: TOP) nokogiri: 4.7344 MiB (Also required by: onelogin/ruby-saml/saml_message, xml_security, and 10 others) rails: 4.0625 MiB (Also required by: active_record/railtie, active_model/railtie, and 14 others) rouge: 16.1953 MiB hamlit: 15.5195 MiB hamlit/template: 10.4531 MiB haml: 10.2734 MiB (Also required by: tilt/haml) haml/engine: 9.0313 MiB haml/buffer: 7.6289 MiB hamlit/engine: 4.9727 MiB (Also required by: hamlit/template) carrierwave: 11.0234 MiB carrierwave/storage: 6.9727 MiB grape: 8.4648 MiB gon: 5.0508 MiB devise: 4.4883 MiB (Also required by: devise-two-factor) sass-rails: 4.0781 MiB sass/rails: 4.0742 MiB ```
issue