[Enhancement] Capture the number of rows instantiated#585
Merged
nateberkopec merged 1 commit intoMiniProfiler:masterfrom Dec 6, 2023
Merged
[Enhancement] Capture the number of rows instantiated#585nateberkopec merged 1 commit intoMiniProfiler:masterfrom
nateberkopec merged 1 commit intoMiniProfiler:masterfrom
Conversation
This is close to telling you the number of rows brought back from the database It doesn't show pluck results, so just need to keep that in mind. But it does help you understand why so much memory is being taken up from active record queries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
This uses active support notifications to capture the number of active record objects instantiated.
Useful?
If you just look at the number of queries, doing a bunch of outer joins looks like a great optimization.
But if you take into account the amount of data brought back, it keeps that over simplification in check.
I have been using this for >7 years and it is a key metric for me.
So I'm putting it out there and see if it is useful to others, as well.
Shortcoming
This only captures instantiation
Model.where(:category => 5).limit(20).select(:name)- capturesModel.where(:category => 5).limit(20).pluck(:name)- doesn't captureSince instantiations are a majority of our use cases, I've only seen a handful of cases where the
pluckmisrepresented a PR or an issue.This is only for active record notifications
I only implemented this for
ActiveSupport::Notifications. It could be done for the others, but I'd prefer to gauge demand before implementing this for every patch configuration.This isn't in the ui
I use the command line to view the results, so I haven't coded this into the ui.
If that is needed, would like a little help.