rails/rails — pull request #7064 by grosser (2012-07-15 23:14:34+00:00)
Title: Do not eager load models that are observerd

Observers are one of the few things eager-loading stuff, whereas associations/helpers etc are all lazy.

this pull adds lazy_observe to Observer, so that models can be observed when they are loaded and not when observers are loaded.

in our app: rails c loads 45 AR models,
with lazy_observe this can be reduced to 0

loadtime:
45 -> 14.2s
0 -> 12.0s

- faster application startup
- less memory on startup
- less db queries on startup
- gems can do their monkey-patching safely before models are loaded
- easier to fork+test since less is loaded (spork / spin)
- can boot an application with a database that is in a bad state (before migration / columns missing etc)

this pull is still missing tests, I'll convert the tests from https://github.com/grosser/lazy_observers if there is a consensus that this is wanted feature.