5

Make ActiveRecord::Base.logger a class_attribute by casperisfine · Pull Request...

 2 years ago
source link: https://github.com/rails/rails/pull/42237
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Contributor

casperisfine commented on May 17

cattr_accessor rely on class variables which has terrible
performance on long ancestor chains. See https://bugs.ruby-lang.org/issues/17763
for a detailed description of the problem.

In comparison class_attribute on ActiveRecord::Base is almost 7x
faster:

Calculating -------------------------------------
              logger      1.700M (± 0.9%) i/s -      8.667M in   5.097595s
             clogger     11.556M (± 0.9%) i/s -     58.806M in   5.089282s

Comparison:
             clogger: 11555754.2 i/s
              logger:  1700280.4 i/s - 6.80x  (± 0.00) slower

This is because ActiveRecord::Base.ancestors.size == 62.

Other cattr usages on ActiveRecord::Base should be considered too, but logger is by far the biggest hostspot, so probably the best one to start the discussion.

@eileencodes @jhawthorn @tenderlove @rafaelfranca


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK