From 0b9bf2e2df2f3e17cad25f4f5e5184fbd0191129 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 15 Feb 2018 18:14:57 +1100 Subject: [PATCH] PERF: symbolize ivar, to reduce dupes I noticed this in my memory profiler report. ``` 153 "@default_url_options" 152 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.1.4/lib/active_support/core_ext/class/attribute.rb:84 ``` 152 copies of the string `@default_url_options` are retained on the heap in Discourse post boot. Since this is just used for ivar lookups there is no need to use a string. --- activesupport/lib/active_support/core_ext/class/attribute.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 7928efb871..fa33ff945f 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -98,7 +98,7 @@ def class_attribute(*attrs) singleton_class.silence_redefinition_of_method("#{name}?") define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate - ivar = "@#{name}" + ivar = "@#{name}".to_sym singleton_class.silence_redefinition_of_method("#{name}=") define_singleton_method("#{name}=") do |val| -- GitLab