[前][次][番号順一覧][スレッド一覧]

ruby-changes:28284

From: tmm1 <ko1@a...>
Date: Wed, 17 Apr 2013 20:20:33 +0900 (JST)
Subject: [ruby-changes:28284] tmm1:r40336 (trunk): iseq: reduce array allocations for simple sequences

tmm1	2013-04-17 20:20:23 +0900 (Wed, 17 Apr 2013)

  New Revision: 40336

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40336

  Log:
    iseq: reduce array allocations for simple sequences
    
    * compile.c (iseq_add_mark_object): Use new rb_iseq_add_mark_object().
    
    * insns.def (setinlinecache): Ditto.
    
    * iseq.c (rb_iseq_add_mark_object): New function to allocate
      iseq->mark_ary on demand. [Bug #8142]
    
    * iseq.h (rb_iseq_add_mark_object): Ditto.
    
    * iseq.c (prepare_iseq_build): Avoid allocating mark_ary until needed.
    
    * iseq.c (rb_iseq_build_for_ruby2cext): Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/insns.def
    trunk/iseq.c
    trunk/iseq.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40335)
+++ ChangeLog	(revision 40336)
@@ -1,3 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr 17 04:09:19 2013  Aman Gupta  <ruby@t...>
+
+	* compile.c (iseq_add_mark_object): Use new rb_iseq_add_mark_object().
+
+	* insns.def (setinlinecache): Ditto.
+
+	* iseq.c (rb_iseq_add_mark_object): New function to allocate
+	  iseq->mark_ary on demand. [Bug #8142]
+
+	* iseq.h (rb_iseq_add_mark_object): Ditto.
+
+	* iseq.c (prepare_iseq_build): Avoid allocating mark_ary until needed.
+
+	* iseq.c (rb_iseq_build_for_ruby2cext): Ditto.
+
 Wed Apr 17 20:00:18 2013  Tanaka Akira  <akr@f...>
 
 	* ext/socket/rubysocket.h (SOCKLEN_MAX): Defined.
Index: insns.def
===================================================================
--- insns.def	(revision 40335)
+++ insns.def	(revision 40336)
@@ -1237,7 +1237,7 @@ setinlinecache https://github.com/ruby/ruby/blob/trunk/insns.def#L1237
 (VALUE val)
 {
     if (ic->ic_value.value == Qundef) {
-	rb_ary_push(GET_ISEQ()->mark_ary, val);
+	rb_iseq_add_mark_object(GET_ISEQ(), val);
     }
     ic->ic_value.value = val;
     ic->ic_vmstat = GET_VM_STATE_VERSION() - ruby_vm_const_missing_count;
Index: iseq.c
===================================================================
--- iseq.c	(revision 40335)
+++ iseq.c	(revision 40336)
@@ -240,6 +240,17 @@ set_relation(rb_iseq_t *iseq, const VALU https://github.com/ruby/ruby/blob/trunk/iseq.c#L240
     }
 }
 
+void
+rb_iseq_add_mark_object(rb_iseq_t *iseq, VALUE obj)
+{
+    if (!RTEST(iseq->mark_ary)) {
+	iseq->mark_ary = rb_ary_tmp_new(3);
+	OBJ_UNTRUST(iseq->mark_ary);
+	RBASIC(iseq->mark_ary)->klass = 0;
+    }
+    rb_ary_push(iseq->mark_ary, obj);
+}
+
 static VALUE
 prepare_iseq_build(rb_iseq_t *iseq,
 		   VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno,
@@ -262,9 +273,7 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L273
     }
 
     iseq->defined_method_id = 0;
-    iseq->mark_ary = rb_ary_tmp_new(3);
-    OBJ_UNTRUST(iseq->mark_ary);
-    RBASIC(iseq->mark_ary)->klass = 0;
+    iseq->mark_ary = 0;
 
 
     /*
@@ -2064,8 +2073,7 @@ rb_iseq_build_for_ruby2cext( https://github.com/ruby/ruby/blob/trunk/iseq.c#L2073
     iseq->location.label = rb_str_new2(name);
     iseq->location.path = rb_str_new2(path);
     iseq->location.first_lineno = first_lineno;
-    iseq->mark_ary = rb_ary_tmp_new(3);
-    OBJ_UNTRUST(iseq->mark_ary);
+    iseq->mark_ary = 0;
     iseq->self = iseqval;
 
     iseq->iseq = ALLOC_N(VALUE, iseq->iseq_size);
Index: iseq.h
===================================================================
--- iseq.h	(revision 40335)
+++ iseq.h	(revision 40336)
@@ -21,6 +21,7 @@ VALUE rb_iseq_build_from_ary(rb_iseq_t * https://github.com/ruby/ruby/blob/trunk/iseq.h#L21
 			     VALUE exception, VALUE body);
 
 /* iseq.c */
+void rb_iseq_add_mark_object(rb_iseq_t *iseq, VALUE obj);
 VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
 VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc);
 struct st_table *ruby_insn_make_insn_table(void);
Index: compile.c
===================================================================
--- compile.c	(revision 40335)
+++ compile.c	(revision 40336)
@@ -416,7 +416,7 @@ static int https://github.com/ruby/ruby/blob/trunk/compile.c#L416
 iseq_add_mark_object(rb_iseq_t *iseq, VALUE v)
 {
     if (!SPECIAL_CONST_P(v)) {
-	rb_ary_push(iseq->mark_ary, v);
+	rb_iseq_add_mark_object(iseq, v);
     }
     return COMPILE_OK;
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]