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

Deduplicate Active Record reflection names #35921

Merged
merged 1 commit into from
Apr 11, 2019

Conversation

casperisfine
Copy link
Contributor

While reading some memory profiles I noticed some common string duplication in Reflection:

Retained String Report
-----------------------------------
423  "shop"
361  /tmp/bundle/ruby/2.5.0/bundler/gems/rails-9b5401fcc962/activerecord/lib/active_record/reflection.rb:25

Unsurprisingly that 361 maps to the number of belongs_to :shop we have. So since that string is effectively used as a symbol, I think it makes sense to freeze and deduplicate it, also since it's derived from model names, it's likely to be used across Rails and the application codebase.

This won't be a huge saving, even for bigger apps, but it's also a very simple one to implement so it might be worth it.

@rafaelfranca @Edouard-chin

@rafaelfranca rafaelfranca merged commit 644cd44 into rails:master Apr 11, 2019
@rafaelfranca rafaelfranca deleted the deduplicate-activerecord-strings branch April 11, 2019 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants