News for hackers. Stuff that matters.
Re:It's not Ruby that's slow, it's your database by dimgl on Tuesday November 08, 2022 @07:15PM (#33526018)
> Keep all logic out of the database. It already is the slowest point. And hardest to scale up.

That's... weird advice. I think a lot of what happens in Rails projects (based on my very limited experience) is that developers start to rely on this easy syntax that ActiveRecord provides and stop thinking about the queries that the ORM is creating. So you end up with these massive N+1 queries that kill performance.

This is one of the reasons I like to stay away from ORMs at all costs. A majority of what an ORM provides can be solved by a view or a function.

As to Ruby's performance... yeah... it's pretty terrible. We had to completely abandon Docker for Ruby on Rails because the performance was absolutely abysmal, even with VirtioFS enabled.

Re:It's not Ruby that's slow, it's your database by boredtofears on Wednesday November 09, 2022 @02:10AM (#33528343)
That's not a good reason to stay away from ActiveRecord. AR has plenty of ways to write optimal queries (all the way down to raw SQL). That said, green developers often won't ever go that far due to not knowing SQL well enough. No matter what, you gotta have some competency with SQL whether you're using an ORM or not.

Things like DB views come with their own problems and constraints, as well as DB level functions (stored procedures).

Re:It's not Ruby that's slow, it's your database by CoolCold on Wednesday November 09, 2022 @02:18AM (#33528376)
> We had to completely abandon Docker for Ruby on Rails because the performance was absolutely abysmal, even with VirtioFS enabled.

can you share more details on this? not sure I get how any kind of VirtioFS comes into the game here

Re:It's not Ruby that's slow, it's your database by dimgl on Wednesday November 09, 2022 @12:00PM (#33534462)
It's a Docker for Mac issue: https://github.com/docker/roadmap/issues/7
Re:It's not Ruby that's slow, it's your database by CoolCold on Wednesday November 09, 2022 @01:19PM (#33535692)
Thanks, I was thinking you were talking about [production systems] Linux.
Re:It's not Ruby that's slow, it's your database by gls2ro on Wednesday November 09, 2022 @02:41AM (#33528499)
It is good advice to learn SQL.

I would suggest enabling the following two configurations in any Rails project. It should be a must in any new Rails project IMO:

1. Enable `config.active_record.strict_loading_by_default` - this will raise ActiveRecord::StrictLoadingViolationError on almost all cases of N+1 thus forcing the developer to fix it

2. Set `config.active_record.warn_on_records_fetched_greater_than` so that you know when someone will load a lot of records, thus forcing to paginate, load only what is needed ...

I think starting with these two will help mitigate a lot of problems even when using ORM in Rails.

Re:It's not Ruby that's slow, it's your database by codedokode on Wednesday November 09, 2022 @03:16AM (#33528694)
> A majority of what an ORM provides can be solved by a view or a function.

If you want to get a single number or column of numbers - then yes, you can go with an SQL query. But if you need to get data about products in a store, you'll have to fetch the data and create objects for every product. Wow, you have just written an ORM.