On 12/09/12 17:29, Masterleep wrote:
> It could be implemented in Rails by using a container class to hold the
> database field names that are used as the keys inside the AR @attributes
> hash, and reusing the same string object across instances. Those strings
> are frozen anyway so the concern about modification doesn't apply.
>  Based on the ObjectSpace data, that one change would have a large
> impact on the number of allocated subobjects for each AR model instance.

To be honest I think we should just change @attributes to be keyed by
symbols. I don't see that there is a DoS vector in doing this since the
keys aren't going to come from user input (however, I do need to think
about that a bit more before I say so confidently).

I changed @attributes_cache to be keyed by symbols recently which lead
to a nice speed up in attribute access (before then we were creating a
new string every time you call an attribute method).

It should be noted that these things could theoretically be optimised at
the implementation level. I did some benchmarking a while back and there
was no difference between using symbols and strings in @attributes on
JRuby. However on a practical level, I think we should change it.

I'm interested to hear what Mr T. Love thinks.

-- 
http://jonathanleighton.com/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to