Defer the inclusion until after ActiveRecord has been fully loaded, i…#8782
Defer the inclusion until after ActiveRecord has been fully loaded, i…#8782alexsmartens wants to merge 1 commit intoactiveadmin:masterfrom
Conversation
…mproving booting performance and following Rails best practices
There was a problem hiding this comment.
Pull Request Overview
This PR defers the loading of Active Admin components until after ActiveRecord is fully loaded to improve application boot performance. The change uses Rails' ActiveSupport.on_load(:active_record) hook to avoid premature ActiveRecord loading during gem initialization.
Key Changes
- Wraps router initialization in
ActiveSupport.on_load(:active_record)callback - Defers
load!and router application until ActiveRecord is ready - Uses explicit reference to
ActiveAdmin.applicationwithin the callback
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8782 +/- ##
=======================================
Coverage 99.08% 99.08%
=======================================
Files 139 139
Lines 4043 4045 +2
=======================================
+ Hits 4006 4008 +2
Misses 37 37 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thank you for this PR! I'm not sure if Copilot's suggestions are applicable here, and I don't have enough insight to provide a thorough review. I'll leave to others with more expertise to review and make the merging decision |
|
@tagliala I've just commented on Copilot's suggestions. They don't make sense. Can you tag people who could potentially review the PR? |
Strict but fair. I did also downvote the response and added the explanation, hoping that this would help
Done |
|
@alexsmartens thank you. I’d like to see what the problem is first that is caused by not having this. It sounds serious so I wonder why we haven’t seen it reported before. We’ve done something similar so it’s not surprising to add something like this but it would be helpful to know and see what the issue is that it’s addressing. We generate dev and test apps locally in this repo but my guess it’s better to see this in an actual app so you may want to demonstrate the issue with our demo app which lives in its own repository. |
|
@javierjulio I've been looking into optimizing my app boot up time for dev/test environments. The boot profiling indicated that most of the booting time comes from loading gems. I tried to find any commonalities between the slow gems and one commonality is premature loading of
That's when I identified the root cause of the issue and created this PR. In my app, this change reduced For reference, |
|
Hello, sorry for the silence (but as I already mentioned I cannot do to much on this) So this is a performance improvement rather than a bug fix and it also may allow us to fix an issue (that I can't replicate) when I use activeadmin together with an Active Record adapter different than the default one. In fact, under some circumstances, we've seeing I was trying to experiment myself against this branch to see if there are improvements. How do you measure Rails boot time? I'm trying with |
|
hi there, |
|
@alexsmartens no because you haven't replied with what we asked for. We'd like to be able to try this for ourselves to vet the change. Thank you. |
|
Is there anything else other than #8782 (comment)? |
|
Hello again, I would like to test the performance improvements by myself. As I mentioned in my previous comment, I'm not familiar with benchmarks of rails boot, and my attempts to compare results between master and this branch were not successful (no visible gain on a small application) |
Issue Description
The current implementation references
ActiveRecordon gem load which triggers premature loading of Active Record. This can significantly slow down application boot time, especially in development and test environments.Solution
Use Rails recommended ActiveSupport.on_load(:active_record) hook to defer module inclusion until after
ActiveRecordis fully loaded. This improves boot performance and avoids potential load order issues in edge cases.