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 Ruby can delay arbitrarily because Ruby is not a realtime system, 2014-09-02 15:47:53 +00:00
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 * test/csv/test_row.rb: Added some missing tests in CSV. 2014-09-05 09:34:38 +00:00
date test_date.rb: nonsense assertion 2014-09-10 08:25:05 +00:00
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 fix encoding spec 2014-07-25 07:55:58 +00:00
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 * test/minitest/test_minitest_unit.rb: removed obsoleted condition 2014-08-09 01:28:50 +00:00
misc test_ruby_mode.rb: trivial refinement 2014-08-16 06:22:48 +00:00
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 * test/rinda/test_rinda.rb: removed useless assignment variables. 2014-08-29 08:37:39 +00:00
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 test_scanf.rb: include arguments in names 2014-02-27 08:19:48 +00:00
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 test/socket/test_unix.rb (TestSocket_UNIXSocket#test_too_long_path): sockaddr_un.sun_path in AIX is defined as char[1024], so "a" * 300 is not too long. "a" * 3000 would be enough. 2014-10-04 07:11:54 +00:00
stringio stringio.c: ASCII-8BIT StringIO rejects no encodings 2014-09-26 03:52:37 +00:00
strscan strscan.c: encoding in messages 2014-08-03 01:56:31 +00:00
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 test/win32ole/test_win32ole_variant.rb 2014-09-22 11:01:22 +00:00
xmlrpc * test/xmlrpc: Refine log test. 2014-11-09 09:36:33 +00:00
zlib zlib: GzipReader#rewind preserves ZSTREAM_FLAG_GZFILE 2014-08-30 23:53:28 +00:00
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 * lib/find.rb (Find#find): should pass ignore_error option to enumerators. 2014-03-03 15:28:58 +00:00
test_ipaddr.rb * lib/ipaddr.rb: extracted inline tests into test dir. 2014-05-31 07:36:51 +00:00
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 * lib/prime.rb (Prime#prime?): negative numbers can't be primes 2014-05-08 18:22:29 +00:00
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 * lib/set.rb (Set#replace): Check if an object given is enumerable 2014-08-06 11:28:21 +00:00
test_shellwords.rb
test_singleton.rb
test_syslog.rb test/test_syslog.rb (TestSyslog#test_log): In AIX, each output line of LOG_PERROR to stderr has an additional empty line appended, so skip that line. 2014-10-04 07:35:43 +00:00
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_thread.rb: move thread switch test 2014-05-28 03:05:48 +00:00
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