Performance: Gemfile and dependency management
This affects page load speed indirectly by controlling which Ruby gems are loaded and how they impact server response time and asset compilation.
source 'https://rubygems.org' gem 'rails' gem 'pg' gem 'devise' group :development, :test do gem 'pry' gem 'byebug' end group :production do gem 'some-heavy-gem' end
source 'https://rubygems.org' gem 'rails' gem 'pg' gem 'devise' gem 'pry' gem 'byebug' gem 'some-heavy-gem' # All gems loaded in all environments without groups
| Pattern | Server Boot Time | Memory Usage | Asset Compilation | Verdict |
|---|---|---|---|---|
| Load all gems in all environments | High (seconds longer) | High (more memory) | Slower (longer precompile) | [X] Bad |
| Group gems by environment | Low (faster boot) | Low (less memory) | Faster (quicker precompile) | [OK] Good |
Gemfile in a Rails application?gem followed by the gem name in quotes.gem 'devise'. Others are invalid Ruby or Gemfile syntax.group :development do gem 'pry' end group :test do gem 'rspec-rails' end
bundle install --without test?bundle install --without test skips installing gems in the :test group.gem 'faker' to your Gemfile but running bundle install gives an error. Which of these is the most likely cause?bundle install errors after adding a gem, a common cause is that the Gemfile changes were not saved, so bundler sees no new gem.bundle update is not required after adding a gem; bundle install is enough. Adding gem outside Gemfile or not running bundle install contradicts the question.group :test do ... end block in Gemfile ensures gems inside load only in test environment.group :test do
gem 'capybara'
end uses the correct group block syntax. Options A and B use invalid options for gem method. group :production do
gem 'capybara'
end wrongly groups gem under production.Pass the test and this pattern moves unknown