haileys/fast_open_struct
open struct that does not invalidate ruby's method cache every time it is instantiated
{ "createdAt": "2013-04-08T13:30:11Z", "defaultBranch": "master", "description": "open struct that does not invalidate ruby's method cache every time it is instantiated", "fullName": "haileys/fast_open_struct", "homepage": null, "language": "Ruby", "name": "fast_open_struct", "pushedAt": "2015-08-10T11:46:03Z", "stargazersCount": 110, "topics": [], "updatedAt": "2025-08-22T09:39:16Z", "url": "https://github.com/haileys/fast_open_struct"}FastOpenStruct
Section titled “FastOpenStruct”FastOpenStruct is a reimplementation of Ruby’s OpenStruct that avoids invalidating MRI’s method caches on every instantiation.
It should be a drop in replacement for OpenStruct.
Performance
Section titled “Performance”FastOpenStruct is very fast when your OpenStructs tend to have static sets of attributes:
λ ruby -I./lib bench/attribute_lookup.rb user system total realOpenStruct 0.730000 0.000000 0.730000 ( 0.732052)FastOpenStruct 0.220000 0.000000 0.220000 ( 0.224770)λ ruby -I./lib bench/attribute_assignment.rbAttribute assignment: user system total realOpenStruct 1.200000 0.000000 1.200000 ( 1.196867)FastOpenStruct 0.210000 0.000000 0.210000 ( 0.210626)λ ruby -I./lib bench/10_000_instantiations.rb user system total realOpenStruct 0.630000 0.010000 0.640000 ( 0.645598)FastOpenStruct 0.240000 0.000000 0.240000 ( 0.239307)However, if you’re using dynamically set attributes heavily, it’s significantly slower:
λ ruby -I./lib bench/dynamic_attribute_lookup.rbDynamic attribute lookup: user system total realOpenStruct 0.660000 0.000000 0.660000 ( 0.661448)FastOpenStruct 2.170000 0.010000 2.180000 ( 2.174698)λ ruby -I./lib bench/dynamic_attribute_assignment.rbDynamic attribute assignment: user system total realOpenStruct 1.190000 0.000000 1.190000 ( 1.198603)FastOpenStruct 6.020000 0.010000 6.030000 ( 6.015700)Licence
Section titled “Licence”Simplified BSD
Copyright (C) 2013 Charlie Somerville. All rights reserved.All rights reserved.
Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ANDON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.