[Solved] Fast Ruby but slow Rails


1.Why “rails” command is very slower than “ruby”?

ruby invokes the Ruby interpreter, which is a compiled executable.

rails invokes the Ruby interpreter plus loads many Ruby libraries that need to be located then parsed by the interpreter, before executing your Rails command. So rails --version will always take longer than ruby --version because it does the same as it plus more.

2.Can we make “rails” command fast as “ruby” command?

Not easily, but this is not usually considered a priority performance issue, because the library loading typically happens once per process – meaning web server requests are not delayed by it, just server start-up time.

Ruby and Rails programs can and do have real performance issues that are normally better to focus on. For instance, they may limit how many concurrent requests that your web server can cope with, and that in turn will affect the costs of running your service. The usual tools for dealing with those practical issues are:

  1. Benchmarking – measuring your performance problem in a standard repeatable way, so you can tell how well you are doing when making improvements. Ruby’s benchmark standard library is a good place to start with this.

  2. Profiling – inspecting which parts of the code are performing badly, so you get some clues on how to fix things. You might look at the gem ruby-prof for this.

It takes some research and practice to learn how to do this effectively, and they are very broad subjects, too much for a Stack Overflow answer. If you want to get started, do a web search for “Ruby Benchmarking” or “Rails Profiling”. Best to start when you have a practical problem to solve.

0

solved Fast Ruby but slow Rails