diff options
| author | wangjohn <wangjohn@mit.edu> | 2013-05-02 16:16:18 -0400 | 
|---|---|---|
| committer | wangjohn <wangjohn@mit.edu> | 2013-05-02 17:16:02 -0400 | 
| commit | 58151ce461e559b7ba8a05a2fa9c9628f19c771b (patch) | |
| tree | cf844ad8515bfb451152aa66736594bbd4a0606a /guides/code/getting_started/db | |
| parent | 6a5ab08d21c4284a05f5e34484b18a91d4e5c50c (diff) | |
| download | rails-58151ce461e559b7ba8a05a2fa9c9628f19c771b.tar.gz rails-58151ce461e559b7ba8a05a2fa9c9628f19c771b.tar.bz2 rails-58151ce461e559b7ba8a05a2fa9c9628f19c771b.zip  | |
Improving the performance of callbacks by keeping a hash of the
callbacks in the CallbackChain, so you don't have to iterate over all
callbacks when checking for duplicates.
Benchmark results when the tests in
activerecord/test/cases/associations_test.rb were run with and without
the change:
== On master (when scanning all of the callbacks):
 ---------------------------------------------------------
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 ---------------------------------------------------------
  1.85     9.26      0.82    18412     0.04     0.05
ActiveSupport::Callbacks::Callback#matches?
  1.22    12.32      0.54    18412     0.03     0.08
ActiveSupport::Callbacks::Callback#duplicates?
  0.93    14.61      0.41    19600     0.02     0.21
ActiveSupport::Callbacks::CallbackChain#remove_duplicates
Finished tests in 1.217065s, 30.4010 tests/s, 53.4072 assertions/s.
 ---------------------------------------------------------
== On my branch (when using a hash to check callback duplication):
 ---------------------------------------------------------
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 ---------------------------------------------------------
  0.15    29.63      0.06     1188     0.05     0.72
ActiveSupport::Callbacks::CallbackChain#handle_duplicates
  0.00    40.50      0.00       84     0.00     0.12
ActiveSupport::Callbacks::Callback#matches?
  0.00    40.50      0.00       84     0.00     0.12
ActiveSupport::Callbacks::Callback#duplicates?
  0.00    40.50      0.00       91     0.00     0.22
ActiveSupport::Callbacks::CallbackChain#scan_and_remove_duplicates
Finished tests in 1.117757s, 33.1020 tests/s, 58.1522 assertions/s.
 ---------------------------------------------------------
Diffstat (limited to 'guides/code/getting_started/db')
0 files changed, 0 insertions, 0 deletions
