I have a Ruby 2.7.6 app running on Heroku (stack heroku-20) and a branch of the same app on Ruby 3.1.4 running on Heroku (stack heroku-22). Both have identical DBs. Running these two branches locally, DB query times seem similar. However on Heroku, DB queries on the Ruby 3 build are massively (sometimes over 10x) slower.
# Ruby 2.7.6 on Heroku-20
participant_registration.session_results.count
D, [2023-07-15T15:10:25.598762 #2] DEBUG -- : (85.0ms) SELECT COUNT(*) FROM "session_results" WHERE "session_results"."sessionable_id" = $1 AND "session_results"."sessionable_type" = $2 [["sessionable_id", 82497], ["sessionable_type", "UserChampionship"]]
# Ruby 3.1.4 on Heroku-22
participant_registration.session_results.count
D, [2023-07-15T15:10:43.115159 #2] DEBUG -- : (1167.6ms) SELECT COUNT(*) FROM "session_results" WHERE "session_results"."sessionable_id" = $1 AND "session_results"."sessionable_type" = $2 [["sessionable_id", 82497], ["sessionable_type", "UserChampionship"]]
All queries are significantly slower, I just chose this one as it seemed even more dramatic than others. Perhaps this is a question I need to raise with Heroku, but I just wanted to check if there was something else I am missing here that I should be aware of.
UPDATE Turns out something must have just gone wrong with the DB on this particular environment. After deleting and rebuilding (with the same production data), it's snappy again.