1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/ruby
normal 65651b34b1 struct: avoid all O(n) behavior on access
This avoids O(n) on lookups with structs over 10 members.
This also avoids O(n) behavior on all assignments on Struct members.
Members 0..9 still use existing C methods to read in O(1) time

Benchmark results:

vm2_struct_big_aref_hi*	1.305
vm2_struct_big_aref_lo*	1.157
vm2_struct_big_aset*	3.306
vm2_struct_small_aref*	1.015
vm2_struct_small_aset*	3.273

Note: I chose use loading instructions from an array instead of writing
directly to linked-lists in compile.c for ease-of-maintainability.  We
may move the method definitions to prelude.rb-like files in the future.

I have also tested this patch with the following patch to disable
the C ref_func methods and ensured the test suite and rubyspec works

	--- a/struct.c
	+++ b/struct.c
	@@ -209,7 +209,7 @@ setup_struct(VALUE nstr, VALUE members)
		ID id = SYM2ID(ptr_members[i]);
		VALUE off = LONG2NUM(i);

	-	if (i < N_REF_FUNC) {
	+	if (0 && i < N_REF_FUNC) {
		    rb_define_method_id(nstr, id, ref_func[i], 0);
		}
		else {

* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset):
  new methods to generate bytecode for struct.c
  [Feature #10575]
* struct.c (rb_struct_ref, rb_struct_set): remove
  (define_aref_method, define_aset_method): new functions
  (setup_struct): use new functions
* test/ruby/test_struct.rb: add test for struct >10 members
* benchmark/bm_vm2_struct_big_aref_hi.rb: new benchmark
* benchmark/bm_vm2_struct_big_aref_lo.rb: ditto
* benchmark/bm_vm2_struct_big_aset.rb: ditto
* benchmark/bm_vm2_struct_small_aref.rb: ditto
* benchmark/bm_vm2_struct_small_aset.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-09 15:43:49 +00:00
..
enc euckr-tbl.rb: euro and registered signs 2014-08-19 13:22:46 +00:00
allpairs.rb
beginmainend.rb
endblockwarn_rb
lbtest.rb
marshaltestlib.rb
sentence.rb
test_alias.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_argf.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_arity.rb
test_array.rb test/ruby: suppress warnings 2014-11-29 00:36:33 +00:00
test_assignment.rb compile.c: private reader in op_assign 2014-07-19 03:40:52 +00:00
test_autoload.rb * test/ruby/test_autoload.rb (class TestAutoload): change load target 2014-11-26 13:31:23 +00:00
test_backtrace.rb test/ruby: fix leaked threads 2014-05-26 05:38:10 +00:00
test_basicinstructions.rb
test_beginendblock.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_bignum.rb
test_call.rb vm_insnhelper.c: disable fastpath if splat 2014-03-12 02:19:13 +00:00
test_case.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_class.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_clone.rb
test_comparable.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_complex.rb * test/ruby/test_complex.rb: removed unreachable code. 2014-08-27 00:58:16 +00:00
test_complex2.rb
test_complexrational.rb
test_condition.rb
test_const.rb * test/ruby/test_const.rb (TestConst#test_redefinition_memory_leak): extend the 2014-11-29 06:01:49 +00:00
test_continuation.rb test/ruby: suppress warnings 2014-11-29 00:36:33 +00:00
test_defined.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_dir.rb safe.c: preserve encoding 2014-11-25 18:43:58 +00:00
test_dir_m17n.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_econv.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_encoding.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_enum.rb test/ruby: suppress warnings 2014-11-29 00:36:33 +00:00
test_enumerator.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_env.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_eval.rb * test/ruby/test_eval.rb: add case to test "sticky" instance_eval 2014-12-02 18:22:15 +00:00
test_exception.rb * test_exception.rb: indent. 2014-11-29 06:00:19 +00:00
test_fiber.rb test/ruby: suppress warnings 2014-11-29 00:36:33 +00:00
test_file.rb safe.c: preserve encoding 2014-11-25 18:43:47 +00:00
test_file_exhaustive.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_fixnum.rb add assertions for division NaN 2014-08-01 07:35:34 +00:00
test_flip.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_float.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_fnmatch.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_gc.rb * test/ruby/test_gc.rb (test_latest_gc_info): do test separately 2014-11-26 11:00:19 +00:00
test_hash.rb parse.y: fix lex_state after tLABEL_END 2014-12-05 00:46:08 +00:00
test_ifunless.rb
test_integer.rb
test_integer_comb.rb
test_io.rb io.c: preserve encodings 2014-11-23 17:03:08 +00:00
test_io_m17n.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_iseq.rb iseq.c: preserve encoding at disassembling 2014-11-23 17:03:32 +00:00
test_iterator.rb
test_keyword.rb * vm_args.c: fix backtrace location for keyword related exceptions. 2014-11-27 10:15:47 +00:00
test_lambda.rb vm_insnhelper.c: allow to_ary 2014-10-30 02:16:15 +00:00
test_lazy_enumerator.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_literal.rb parse.y: fix literal symbol list node type 2014-11-18 19:16:27 +00:00
test_m17n.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_m17n_comb.rb string.c: raise at invalid byte sequence 2014-07-22 04:33:38 +00:00
test_marshal.rb marshal.c: fix symlink index 2014-07-29 03:28:43 +00:00
test_math.rb test_math.rb: use Float#infinite? 2014-09-19 01:47:06 +00:00
test_metaclass.rb
test_method.rb vm_eval.c: preserve encoding 2014-11-25 18:44:07 +00:00
test_mixed_unicode_escapes.rb
test_module.rb test_module.rb: fix encoding 2014-11-18 01:38:50 +00:00
test_not.rb
test_notimp.rb
test_numeric.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_object.rb vm_method.c: preserve encodings 2014-11-25 18:58:05 +00:00
test_objectspace.rb thread.c: get rid of invalid ID symbol 2014-12-09 01:16:27 +00:00
test_optimization.rb test/ruby/test_optimization.rb (test_string_size): new test 2014-10-14 22:01:54 +00:00
test_pack.rb pack.c: escape and encoding 2014-11-06 14:58:43 +00:00
test_parse.rb parse.y: invalid instance/class variable names 2014-11-01 06:45:17 +00:00
test_path.rb
test_pipe.rb io.c: truncate before appending 2014-06-07 03:51:57 +00:00
test_primitive.rb
test_proc.rb proc.c: fix method proc binding location 2014-11-16 21:13:10 +00:00
test_process.rb * test/ruby/test_process.rb (test_deadlock_by_signal_at_forking): 2014-11-30 09:57:04 +00:00
test_rand.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_range.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_rational.rb * test/ruby/test_complex.rb: removed unreachable code. 2014-08-27 00:58:16 +00:00
test_rational2.rb
test_readpartial.rb normalize reference to Timeout::Error 2014-10-07 20:00:09 +00:00
test_refinement.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_regexp.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_require.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_rubyoptions.rb test_rubyoptions.rb: non-codepage names glob 2014-12-05 11:37:10 +00:00
test_rubyvm.rb vm.c: avoid inadvertent pin-down 2014-03-31 02:34:40 +00:00
test_settracefunc.rb * compile.c (iseq_compile_each): remove duplicated line event. 2014-11-27 11:06:51 +00:00
test_signal.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_sleep.rb I suspect such early wakeup is because of automatic time correction 2014-05-22 10:42:06 +00:00
test_sprintf.rb sprintf.c: improve rational 'f' format 2014-09-14 23:13:36 +00:00
test_sprintf_comb.rb
test_string.rb string.c: preserve encoding of global variable 2014-11-23 17:03:48 +00:00
test_stringchar.rb
test_struct.rb struct: avoid all O(n) behavior on access 2014-12-09 15:43:49 +00:00
test_super.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_symbol.rb symbol.c: fix dynamic attrset ID 2014-09-19 11:06:04 +00:00
test_syntax.rb iseq.c: avoid segfault on incomplete iseq 2014-12-03 22:03:59 +00:00
test_system.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_thread.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_threadgroup.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_time.rb add an assertion. 2014-11-15 15:33:34 +00:00
test_time_tz.rb * test/ruby/test_time_tz.rb: Fix test error with tzdata-2014g. 2014-09-22 03:12:23 +00:00
test_trace.rb
test_transcode.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_undef.rb
test_unicode_escape.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_variable.rb test_variable.rb: suppress warnings 2014-11-22 23:47:22 +00:00
test_weakmap.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_whileuntil.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_yield.rb test_yield.rb: use temporary instance 2014-09-13 00:47:02 +00:00
ut_eof.rb