1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test
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
..
-ext- mostly fix rb_iseq_load 2014-12-03 22:16:58 +00:00
base64
benchmark
bigdecimal * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
cgi * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
coverage
csv
date
dbm * test/ruby/test_object.rb: Specify an exception class for rescue clause. 2014-11-11 15:28:17 +00:00
digest Make Digest() thread-safe. 2014-10-31 13:21:51 +00:00
drb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
dtrace * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
erb
etc win32.c: login name encoding 2014-11-10 08:24:36 +00:00
fiddle * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
fileutils * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
gdbm * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
io * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
irb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
json * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
lib envutil.rb: skip if load failed 2014-11-27 03:42:32 +00:00
logger * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
matrix test_vector.rb: fix exception class 2014-11-19 23:57:56 +00:00
minitest
misc
mkmf * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
monitor * test/monitor/test_monitor.rb: Use assert_join_threads. 2014-11-13 13:04:43 +00:00
net * test/net/imap/test_imap.rb (ImapTest#imaps_test): forced error on SSL sockets 2014-12-07 13:59:17 +00:00
nkf
objspace * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
open-uri * test/open-uri: Test server log in server thread. 2014-11-09 14:01:20 +00:00
openssl * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
optparse
ostruct
pathname * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
psych * ext/psych/lib/psych/visitors/to_ruby.rb: support objects that are 2014-12-01 21:35:11 +00:00
rake * lib/rake: Update to rake 10.4.2 2014-12-06 00:22:51 +00:00
rdoc * lib/rdoc: Update to RDoc 4.2.0. 2014-12-07 01:22:37 +00:00
readline * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
resolv * lib/resolv.rb: fall back if canonicalization fails. 2014-11-21 20:04:27 +00:00
rexml * test/rexml/test_document.rb: Indent. 2014-11-15 12:29:21 +00:00
rinda * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
ripper parse.y: preserve tSTRING_CONTENT results 2014-12-01 21:32:04 +00:00
rss
ruby struct: avoid all O(n) behavior on access 2014-12-09 15:43:49 +00:00
rubygems * lib/rubygems: Update to RubyGems 2.4.5. 2014-12-07 00:53:01 +00:00
scanf
sdbm * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
shell * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
socket
stringio
strscan
syslog
testunit * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
thread * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
uri * lib/uri/generic.rb (URI::Generic.build): 2014-12-01 17:36:54 +00:00
webrick * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
win32ole
xmlrpc * test/xmlrpc: Refine log test. 2014-11-09 09:36:33 +00:00
zlib
runner.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_abbrev.rb
test_cmath.rb
test_delegate.rb
test_find.rb
test_ipaddr.rb
test_mathn.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_mutex_m.rb
test_open3.rb * test/test_open3.rb: Add a simple test for env hash on popen3. 2014-12-02 22:08:05 +00:00
test_pp.rb * test/test_pp.rb (PPTestModule::PPFileStatTest): test for r48719. 2014-12-05 19:48:15 +00:00
test_prettyprint.rb
test_prime.rb
test_pstore.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_pty.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_rbconfig.rb
test_securerandom.rb
test_set.rb
test_shellwords.rb
test_singleton.rb
test_syslog.rb
test_tempfile.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_time.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_timeout.rb
test_tmpdir.rb
test_tracer.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00
test_tsort.rb * lib/tsort.rb: Returns an enumerator if no block is given. 2014-11-26 10:46:50 +00:00
test_unicode_normalize.rb test_unicode_normalize.rb: skip only once 2014-11-11 23:54:45 +00:00
test_weakref.rb * test/lib/envutil.rb: Moved from test/ruby/. 2014-11-13 16:05:37 +00:00