ActiveRecord::Core#initialize: improve performance #5467

merged 1 commit into from Mar 16, 2012


None yet
2 participants

bogdan commented Mar 16, 2012

According to this article:

AR initialization callbacks are slow even if we don't use them.
I didn't find a way to improve performance in AS::Callbacks level.

So, Here is what we can do to avoid going into run_callbacks if we don't use them.

Benchmark file:
Super funny benchmark tool: diffbench

Running benchmark with current working tree
Checkout HEAD^
Running benchmark with HEAD^
Checkout to previous HEAD again

----------simple initialize----------
After patch:   0.160000   0.000000   0.160000 (  0.159779)
Before patch:   0.210000   0.010000   0.220000 (  0.216816)

----------initialize with attributes----------
After patch:   0.610000   0.000000   0.610000 (  0.623824)
Before patch:   0.660000   0.000000   0.660000 (  0.663776)

josevalim added a commit that referenced this pull request Mar 16, 2012

Merge pull request #5467 from bogdan/initialize_callbacks
ActiveRecord::Core#initialize: improve performance

@josevalim josevalim merged commit 6d0047a into rails:master Mar 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment