Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, are many gems in gemfile slowing down the site?

I'm wondering if having many gems in the Gemfile are slowing down the site? Are they loaded when needed or are all loaded at every page request?

like image 580
jonepatr Avatar asked Mar 20 '11 01:03

jonepatr


People also ask

What is a gem Gemfile?

A Gemfile is a file that is created to describe the gem dependencies required to run a Ruby program. A Gemfile should always be placed in the root of the project directory.

What is gem require false?

You use :require => false when you want the gem to be installed but not "required". So in the example you gave: gem 'whenever', :require => false when someone runs bundle install the whenever gem would be installed as with gem install whenever .

What does Gemfile lock do?

The Gemfile. lock allows you to specify the versions of the dependencies that your application needs in the Gemfile , while remembering all of the exact versions of third-party code that your application used when it last worked correctly. By specifying looser dependencies in your Gemfile (such as nokogiri ~> 1.4.

What can you do with Gemfile?

Your gemfile is a list of all gems that you want to include in the project. It is used with bundler (also a gem) to install, update, remove and otherwise manage your used gems. These gems belong to development environment and the test environment since they are for testing the application.


2 Answers

It really depends on what gems you are using (i.e. middleware vs. just some small library). However in the general case, more gems = more code to process = more time = slower site.

One tip that I can suggest to you is in your Gemfile, do something like this:

gem 'gemname', :require => false

To not have rails require this gem on startup. The downside of course is that you have to manually call require 'gemname' whenever you want to use that gem. It's all a balance of performance vs. ease of use.

like image 51
Mike Lewis Avatar answered Oct 20 '22 12:10

Mike Lewis


Bundler what is the require false on the gemfile means

I think that will answer your question.

like image 38
Linus Oleander Avatar answered Oct 20 '22 11:10

Linus Oleander