diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-05-29 06:45:34 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-06-01 22:48:57 +0900 |
commit | 613060d106f2d3bf7350bab540c952b1567ad66b (patch) | |
tree | 4cf6847bf553c8fe7f49d75755109441e9a7a4fc /actionmailbox/app | |
parent | 2a015f6c0be0593a624b0c800e5335319ac4c660 (diff) | |
download | rails-613060d106f2d3bf7350bab540c952b1567ad66b.tar.gz rails-613060d106f2d3bf7350bab540c952b1567ad66b.tar.bz2 rails-613060d106f2d3bf7350bab540c952b1567ad66b.zip |
Avoid making extra 5 arrays in each `save`
Each `save` calls `all_timestamp_attributes_in_model` to fill timestamp
columns. Allthough the `all_timestamp_attributes_in_model` returns the
same value every time, the `all_timestamp_attributes_in_model` makes
extra 5 arrays every time.
This avoids the making extra 5 arrays by memoizing the result, it makes
`save` economical and a bit faster.
https://gist.github.com/kamipo/1ddad2235073f508637bf9a72d64bb83
Before (2a015f6c0be0593a624b0c800e5335319ac4c660):
```
{["~/rails/activerecord/lib/active_record/timestamp.rb",
76,
:T_ARRAY]=>[1000, 0, 341, 0, 1, 13640],
["~/rails/activerecord/lib/active_record/timestamp.rb",
64,
:T_ARRAY]=>[1000, 0, 341, 0, 1, 13640],
["~/rails/activerecord/lib/active_record/timestamp.rb",
80,
:T_ARRAY]=>[1000, 0, 341, 0, 1, 13640],
["~/rails/activerecord/lib/active_record/timestamp.rb",
68,
:T_ARRAY]=>[1000, 0, 341, 0, 1, 13640],
["~/rails/activerecord/lib/active_record/timestamp.rb",
73,
:T_ARRAY]=>[1000, 0, 341, 0, 1, 13640]}
Warming up --------------------------------------
User.create * 10 36.000 i/100ms
Calculating -------------------------------------
User.create * 10 353.644 (± 7.4%) i/s - 1.764k in 5.021876s
```
After (this change):
```
{["~/rails/activerecord/lib/active_record/timestamp.rb",
83,
:T_ARRAY]=>[1, 0, 1, 1, 1, 40],
["~/rails/activerecord/lib/active_record/timestamp.rb",
87,
:T_ARRAY]=>[1, 0, 1, 1, 1, 40],
["~/rails/activerecord/lib/active_record/timestamp.rb",
64,
:T_ARRAY]=>[1, 1, 1, 1, 1, 0],
["~/rails/activerecord/lib/active_record/timestamp.rb",
69,
:T_ARRAY]=>[1, 1, 1, 1, 1, 0],
["~/rails/activerecord/lib/active_record/timestamp.rb",
74,
:T_ARRAY]=>[1, 1, 1, 1, 1, 0]}
Warming up --------------------------------------
User.create * 10 37.000 i/100ms
Calculating -------------------------------------
User.create * 10 380.063 (± 7.1%) i/s - 1.924k in 5.097917s
```
Diffstat (limited to 'actionmailbox/app')
0 files changed, 0 insertions, 0 deletions