You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I noticed that after adding the gem, accessing model attributes works slower.
The problem is with setting StoreModel.config.enable_parent_assignment = true, perhaps it's better to set it to false by default.
gem "store_model", require: false
rails runner -e production getters_bench.rb 3.7x slowly
require"benchmark/ips"ActiveRecord::Schema.definedocreate_table:models,force: truedo |t|
t.string:namet.integer:ids,array: truet.timestampsendendclassModel < ActiveRecord::Base;endm=Model.create(name: "name",ids: [1,2,3,4,5])Benchmark.ipsdo |x|
x.report("without store_model"){m.id;m.created_at;m.ids}endrequire"store_model"moduleStoreModel# :nodoc:classRailtie < Rails::Railtie# :nodoc:ActiveSupport.on_load(:active_record)doifStoreModel.config.enable_parent_assignmentActiveModel::Attributes.prepend(Attributes)prepend(Base)endendendendBenchmark.ipsdo |x|
x.report("with store_model"){m.id;m.created_at;m.ids}end# Warming up --------------------------------------# without store_model 193.067k i/100ms# Calculating -------------------------------------# without store_model 1.901M (± 1.3%) i/s - 9.653M in 5.079277s# Warming up --------------------------------------# with store_model 50.543k i/100ms# Calculating -------------------------------------# with store_model 509.177k (± 1.4%) i/s - 2.578M in 5.063416s
rails runner -e production setters_bench.rb 2.6x slowly
classModel < ActiveRecord::Base;endm=Model.create(name: "name",ids: [1,2,3,4,5])new_arr=[1,2,3]Benchmark.ipsdo |x|
x.report("without store_model"){m.ids=new_arr}endrequire"store_model"moduleStoreModel# :nodoc:classRailtie < Rails::Railtie# :nodoc:ActiveSupport.on_load(:active_record)doifStoreModel.config.enable_parent_assignmentActiveModel::Attributes.prepend(Attributes)prepend(Base)endendendendBenchmark.ipsdo |x|
x.report("with store_model"){m.ids=new_arr}end# Warming up --------------------------------------# without store_model 229.502k i/100ms# Calculating -------------------------------------# without store_model 2.298M (± 2.4%) i/s - 11.705M in 5.095917s## Warming up --------------------------------------# with store_model 86.820k i/100ms# Calculating -------------------------------------# with store_model 872.129k (± 1.6%) i/s - 4.428M in 5.078182s
The text was updated successfully, but these errors were encountered:
Hi, I noticed that after adding the gem, accessing model attributes works slower.
The problem is with setting
StoreModel.config.enable_parent_assignment = true
, perhaps it's better to set it tofalse
by default.gem "store_model", require: false
rails runner -e production getters_bench.rb
3.7x slowlyrails runner -e production setters_bench.rb
2.6x slowlyThe text was updated successfully, but these errors were encountered: