Skip to content

Conversation

@casperisfine
Copy link
Contributor

I noticed that the attribute method proxy call would systematically instantiate the same string over and over:

[10] pry(main)> MemoryProfiler.report { s.name? }.pretty_print
# ...
Allocated String Report
-----------------------------------
         1  "name"
         1  ~/gems/rails-1d1991430dc5/activemodel/lib/active_model/attribute_methods.rb:380

It's not a lot per say, but it can easily add up.

Backward compatibility

It's possible that there are attribute methods out there that mutate the received attribute name, but IMHO it's quite an edge case and easy to fix.

cc @rafaelfranca @Edouard-chin

@casperisfine casperisfine force-pushed the attribute-methods-frozen-strings branch from 27484a4 to 1e209d7 Compare January 30, 2020 19:40
@tenderlove
Copy link
Member

ooooo lol, I love it.

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.

3 participants