ManishShrivastava
12-Mar-20206 min read

How to Speed Up Your Ruby on Rails App.

Ruby on rails is extremely popular as it speeds up development. This framework provides developers with a great collection of libraries. But just choosing Ruby on Rails doesn't means your project will succeed. To meet your users expectations, your Ruby on Rails should be fast.

What does it mean?

It means that over half of internet users expect that a page of website should be loads within seconds of time so they can use website efficiently and also it makes interests in them towards website or application. And around three quarters of web users won't return to a website if it takes longer than four seconds to load.

So here are some tips by which you can optimize your Application performance and can increase it as much as possible :-

* Eliminate the N+1 query problem


One of the most frequent causes of slow performance is the N+1 query problem which is faced by many Ruby on Rails application. This is because of using unusual queries which is not needed most of the times. As the project becomes bigger, this problem only compounds. You may find out that your project is running lots of queries to achieve one result rather than running one query with many results.


You need to cut down the independent queries to speedup the performance, So you can use eager loading associated relations. That means you should collect data with one query using eager loading.
You can also use Bullet gem which identifies and reports N+1 queries.


* Use Gems and Plugins


Some gems and plugins solve common problems in Ruby on rails applications so developers don't have to create solutions from scratch. Gems and plugins handle issues connected with APIs, security, Active Record, authentication etc.


But don't forget that lavish using of gems and plugin also degrades the performance of your Ruby on Rails application. So be careful and use gems and plugins wisely in your application.

* Use Background Processing

* Use a content delivery network(CDN)

Use a content delivery network(CDN) no matter which network or framework you use. CDNs are services that provide edge nodes around the world so that files are closer to a user's location. With CDNs, website content like JavaScript, CSS, HTML, images and videos load equally fast in different locations.
* Use indexing to database

A lack of indexes on columns is one of the reasons why some queries take way longer to execute than they should. When creating a database column without indexes the database engine will check every record in the table until it finds a match. With indexes, the lookup will be a lot faster, as the engine will check only specific records.

Indexes speedup the searches but degrades the update process so keep in mind while using indexes to your database table.

* Choose your web hosting provider wisely

That s all for today!, Happy coding