Project

General

Profile

Actions

Bug #11901

closed

Performance Issue with OpenStruct

Added by amcaplan (Ariel Caplan) almost 9 years ago. Updated over 8 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin13]
Backport:
[ruby-core:72523]

Description

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) openstruct-regression-benchmark.rb Benchmark to compare 2.2.4 versus 2.3.0 amcaplan (Ariel Caplan), 12/27/2015 03:35 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0