From: normalperson@... Date: 2014-12-11T23:08:18+00:00 Subject: [ruby-core:66793] [ruby-trunk - Feature #10585] struct: speedup struct.attr = v for first 10 attributes and struct[:attr] for big structs Issue #10585 has been updated by Eric Wong. benchmark results on r48774 (Xeon E3-v1230 v3): Speedup ratio: compare with the result of `trunk' (greater is better) name built loop_whileloop2 1.001 vm2_struct_big_aref_hi* 1.006 vm2_struct_big_aref_lo* 1.000 vm2_struct_big_aset* 1.005 vm2_struct_big_href_hi* 1.466 vm2_struct_big_href_lo* 1.213 vm2_struct_big_hset* 1.305 vm2_struct_small_aref* 1.010 vm2_struct_small_aset* 2.604 vm2_struct_small_href* 1.215 vm2_struct_small_hset* 1.215 Comments on patches: * [1/4] struct.c: speedup struct.name = v for small structs I agree this makes a noticeable improvement, but I am also not in favor of more specialized C code. One day, I hope we can remove the current optimizations for <10 getters with JIT. * [2/4] struct.c: cache member definition in a subclass I think NIL_P(var) is preferred over "var != Qnil". Overall, I think this patch makes sense on its own. * [3/4] benchmark struct[:name] Good :) * [4/4] struct.c: speedup for big structs Oops, I totally missed some of these in [Feature #10575] I'm unsure about having a custom hash table in there is best, perhaps it can be extracted and reused for other things (fstring). ---------------------------------------- Feature #10585: struct: speedup struct.attr = v for first 10 attributes and struct[:attr] for big structs https://bugs.ruby-lang.org/issues/10585#change-50367 * Author: Yura Sokolov * Status: Open * Priority: Normal * Assignee: * Category: core * Target version: current: 2.2.0 ---------------------------------------- 0001 - Define optimized setters for first 10 attributes. 0002 - Cache members definition in an subclasses - it is safe cause it could be modified/overloaded. And use `rb_attr_get` to lookup definition - it is safe cause result is checked later and `Qnil` is treated as error. 0003,0004 - Use custom hash structure (on top of Array) to lookup members index in a big structure. Well, I doubt that big structures are useful, so I will not grieve if 0004 is not accepted. ---Files-------------------------------- 0001-struct.c-speedup-struct.name-v-for-small-structs.patch (2.33 KB) 0002-struct.c-cache-member-definition-in-a-subclass.patch (1.09 KB) 0003-benchmark-struct-name.patch (2.42 KB) 0004-struct.c-speedup-for-big-structs.patch (5.47 KB) -- https://bugs.ruby-lang.org/