Open wulftone opened 12 years ago
This is just a guess, but I think the slow load times are due to CanCan's extensions to ActionController::Base
and ActiveRecord::Base
. Due to Rails' auto-loading behavior, this will trigger the loading of ActionController and ActiveRecord and make it appear that CanCan is slow since it is loading a good chunk of Rails at that time.
The result is that CanCan doesn't actually slow down startup time by that much, it just triggers the loading of Rails earlier on.
The solution would be to use a Railtie with ActiveSupport on_load hooks. I have been planning to do this but haven't gotten around to it.
Note: This is just a theory and is untested.
@wulftone, The bundle benchmarking gist has been updated by the author to include a call to eager load rails. If you re-run that you should see the cost of loading those gems in a world where they aren't responsibile for autoloading required parts of rails. You may see your reported load time go down by quite a bit. In my case, CanCan never accounted for much of the reported load time as there was a gem loaded earlier on that paid the autoload penalty.
It seems that @ryanb's hypothesis is mostly correct. That said, it still may be worthwhile to use a railtie for 2.0.
I concur. I'm seeing cancan forcing the ActiveRecord to load really early,before most other gems register thier ActiveSupport on_load hooks.
In my case the hooks for other gems never run. I am in a peculiar situation though as we are depending on ActiveRecord being fully initialized before the middleware stack is built.
In all cases except mine everything just works. That said, adding a Raltie w/ on_load hooks into ActiveRecord would fix my problem and probably fix for anyone else who is forced to take a trip outside the conventions.
I noticed that when starting rails, cancan takes about 4 times as long as the next slowest library (devise). This isn't critical, but it's noticeable, especially when doing testing and restarting rails a lot. I put a benchmark in my
Kernel
code, and this is what I found out:Is there any way to reduce this?