Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Capture the number of rows instantiated #585

Merged
merged 1 commit into from Dec 6, 2023

Conversation

kbrock
Copy link
Contributor

@kbrock kbrock commented Jun 15, 2023

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) - captures
Model.where(:category => 5).limit(20).pluck(:name) - doesn't capture

Since 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.

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.
@kbrock kbrock changed the title Capture the number of rows instantiated [Enhancement] Capture the number of rows instantiated Jun 15, 2023
@nateberkopec nateberkopec merged commit 0869490 into MiniProfiler:master Dec 6, 2023
5 checks passed
@kbrock kbrock deleted the instantiation_counts branch December 6, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants