From: ariel.caplan@... Date: 2015-12-27T15:48:38+00:00 Subject: [ruby-core:72524] [Ruby trunk - Bug #11901] Performance Issue with OpenStruct Issue #11901 has been updated by Ariel Caplan. Assignee set to Marc-Andre Lafortune To be more specific (but not clog up the description), the problem can be traced to https://github.com/ruby/ruby/blob/b8d9770b6c699af6e63dab727621777fbfbf7b44/lib/ostruct.rb#L166 where the methods are only defined if `#respond_to?` is `false` for that method name. Since `#repond_to_missing?` was overridden to report `true` when the key is in the table (https://github.com/ruby/ruby/blob/b8d9770b6c699af6e63dab727621777fbfbf7b44/lib/ostruct.rb#L176), the methods are never defined. ---------------------------------------- Bug #11901: Performance Issue with OpenStruct https://bugs.ruby-lang.org/issues/11901#change-55788 * Author: Ariel Caplan * Status: Open * Priority: Normal * Assignee: Marc-Andre Lafortune * ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin13] * Backport: ---------------------------------------- After recent changes to define OpenStruct getter/setter methods lazily, there is a heavy performance impact for the use case where an attribute is assigned at initialization time (i.e. `Openstruct.new(foo: :bar)`). Once an attribute is stored in the internal hash, the appropriate singleton methods will never be defined, due to the recent changes to OpenStruct's `#respond_to_missing?` - meaning that every time I call `#foo` or `#foo=` it relies on `#method_missing`. Benchmark using benchmark-ips is attached. I'm primarily concerned about the case of configuration objects, which may be populated at initialization time and then accessed many times throughout the life of the program. ---Files-------------------------------- openstruct-regression-benchmark.rb (1.36 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: