Are Active Records slow?


I often come across developers who argue that using Active Records reduces performance. They claim that raw queries should be utilized instead.

Any thoughts on this?

Has any study been undertaken about performance of ARs and the possible consequences of replacing them with raw queries?


1 Like
  1. That’s true that AR consumes extra CPU/memory compared to direct low-level queries. Also, if you know to optimally write SQL query, you’ll likely do it better than AR does.
  2. In majority of cases that’s no an issue thohgh. Either it’s not that many records selected or it’s an update/insert/delete where AR doesn’t produce any signficant overhead (unless that’s large batch import).
  3. In case of saving a record, AR produces optimal query considering fields that were not changed and that’s a bit more efficient than saving everything all the time and that’s what is usually done when not using AR.
  1. AR consumes less effort and time of the developer than low-level SQL queries. From the developer’s cost-performance view point, it’s not very wise to optimize the queries by raw SQL in many of the use cases.

From my long experience in this domain, I would suggest to use ARs or any core feature in your framework because they are safer and have more features built in and focus on caching technologies when you go to productions… optimizing your code is must in either cases.

Best of luck!