[Enhancement] Capture the number of rows instantiated #585
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
pluck
misrepresented 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.