rails/rails — pull request #4493 by bogdan (2012-01-17 10:09:58+00:00)
Title: AS::Callbacks: Refactor :per_key option

I suppose that `:per_key` option was originally designed to improve performance of `(before/after/around)_filter` in `ActionController`. Maybe someone who is in Rails core team since 2009 can explain why this option appeared.

But now when overall performance issue was fixed, we can rewrite it with 3 lines of code using other code we have.

Performance test: https://gist.github.com/1626009

**19% performance improvement** on `set_callback`
**19% performance improvement** on `run_callbacks` with `:per_key` option
**15% performance improvement** on `skip_callback`

Checked tests for AR, AM and AP to ensure everything is fine.

```
Rehearsal ----------------------------------------------------
New set_callback 0.050000 0.000000 0.050000 ( 0.045225)
Old set_callback 0.050000 0.010000 0.060000 ( 0.056748)
------------------------------------------- total: 0.110000sec

user system total real
New set_callback 0.040000 0.000000 0.040000 ( 0.043966)
Old set_callback 0.050000 0.000000 0.050000 ( 0.053711)
************************************************************************************************************************
Rehearsal --------------------------------------------------------
New define_callbacks 0.020000 0.000000 0.020000 ( 0.019756)
Old define_callbacks 0.020000 0.000000 0.020000 ( 0.019723)
----------------------------------------------- total: 0.040000sec

user system total real
New define_callbacks 0.010000 0.010000 0.020000 ( 0.019719)
Old define_callbacks 0.020000 0.010000 0.030000 ( 0.019841)
************************************************************************************************************************
Rehearsal -----------------------------------------------------
New run_callbacks 0.000000 0.000000 0.000000 ( 0.004363)
Old run_callbacks 0.010000 0.000000 0.010000 ( 0.005427)
-------------------------------------------- total: 0.010000sec

user system total real
New run_callbacks 0.000000 0.000000 0.000000 ( 0.004433)
Old run_callbacks 0.010000 0.000000 0.010000 ( 0.005051)
************************************************************************************************************************
Rehearsal --------------------------------------------------------------
New run_callbacks with key 0.000000 0.000000 0.000000 ( 0.000471)
Old run_callbacks with key 0.000000 0.000000 0.000000 ( 0.001329)
----------------------------------------------------- total: 0.000000sec

user system total real
New run_callbacks with key 0.000000 0.000000 0.000000 ( 0.000473)
Old run_callbacks with key 0.000000 0.000000 0.000000 ( 0.000570)
************************************************************************************************************************
Rehearsal -----------------------------------------------------
New skip_callback 0.020000 0.010000 0.030000 ( 0.029028)
Old skip_callback 0.030000 0.000000 0.030000 ( 0.033500)
-------------------------------------------- total: 0.060000sec

user system total real
New skip_callback 0.030000 0.000000 0.030000 ( 0.028263)
Old skip_callback 0.030000 0.000000 0.030000 ( 0.033339)

```