Rails 7 moves ActiveRecord::Base.logger to a class_attribute leading to a 7x speed improvement

In our opinion, this PR provides one of the simplest yet most performant speed improvements to Rails 7. Ruby recently introduced an inline cache for class variable reads. This allows for values to be read from the cache instead of traversing a complex inheritance tree to resolve a class variable value. When class variables are read, Ruby needs to check each class in the inheritance tree to ensure that the class variable isn’t set on any other classes in the tree.

As you can imagine this becomes an O(n) problem. As the number of nodes increases in a tree, the read performance degrades linearly.

Let’s look at a demonstration using a class that inherits 1 module, 30 modules and finally 100 modules…

Read in full here:

This thread was posted by one of our members via one of our news source trackers.