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

ruby-changes:42902

From: tarui <ko1@a...>
Date: Wed, 11 May 2016 21:50:44 +0900 (JST)
Subject: [ruby-changes:42902] tarui:r54976 (trunk): * compile.c (iseq_compile_each): share InlineCache during same

tarui	2016-05-11 21:50:38 +0900 (Wed, 11 May 2016)

  New Revision: 54976

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54976

  Log:
    * compile.c (iseq_compile_each): share InlineCache during same
      instance variable accesses. Reducing memory consumption,
      rasing cache hit rate and rasing branch prediction hit rate
      are expected. A part of [Bug #12274].
    
    * iseq.h (struct iseq_compile_data): introduce instance
      variable IC table for sharing.
    
    * iseq.c (prepare_iseq_build, compile_data_free):
      construct/destruct above table.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/iseq.c
    trunk/iseq.h
Index: compile.c
===================================================================
--- compile.c	(revision 54975)
+++ compile.c	(revision 54976)
@@ -1542,6 +1542,19 @@ cdhash_set_label_i(VALUE key, VALUE val, https://github.com/ruby/ruby/blob/trunk/compile.c#L1542
     return ST_CONTINUE;
 }
 
+
+static inline VALUE
+get_ivar_ic_value(rb_iseq_t *iseq,ID id)
+{
+    VALUE val;
+    st_table *tbl = ISEQ_COMPILE_DATA(iseq)->ivar_cache_table;
+    if(!st_lookup(tbl,(st_data_t)id,&val)){
+	val = INT2FIX(iseq->body->is_size++);
+	st_insert(tbl,id,val);
+    }
+    return val;
+}
+
 /**
   ruby insn object list -> raw instruction sequence
  */
@@ -4604,7 +4617,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4617
 	    ADD_INSN(ret, line, dup);
 	}
 	ADD_INSN2(ret, line, setinstancevariable,
-		  ID2SYM(node->nd_vid), INT2FIX(iseq->body->is_size++));
+		  ID2SYM(node->nd_vid),
+		  get_ivar_ic_value(iseq,node->nd_vid));
 	break;
       }
       case NODE_CDECL:{
@@ -5415,7 +5429,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5429
 	debugi("nd_vid", node->nd_vid);
 	if (!poped) {
 	    ADD_INSN2(ret, line, getinstancevariable,
-		      ID2SYM(node->nd_vid), INT2FIX(iseq->body->is_size++));
+		      ID2SYM(node->nd_vid),
+		      get_ivar_ic_value(iseq,node->nd_vid));
 	}
 	break;
       }
@@ -8474,4 +8489,3 @@ iseq_ibf_load_extra_data(VALUE str) https://github.com/ruby/ruby/blob/trunk/compile.c#L8489
     RB_GC_GUARD(loader_obj);
     return extra_str;
 }
-
Index: iseq.c
===================================================================
--- iseq.c	(revision 54975)
+++ iseq.c	(revision 54976)
@@ -58,6 +58,8 @@ compile_data_free(struct iseq_compile_da https://github.com/ruby/ruby/blob/trunk/iseq.c#L58
 	    ruby_xfree(cur);
 	    cur = next;
 	}
+	st_free_table(compile_data->ivar_cache_table);
+
 	ruby_xfree(compile_data);
     }
 }
@@ -298,6 +300,8 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L300
     ISEQ_COMPILE_DATA(iseq)->option = option;
     ISEQ_COMPILE_DATA(iseq)->last_coverable_line = -1;
 
+    ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = st_init_numtable();
+
     if (option->coverage_enabled) {
 	VALUE coverages = rb_get_coverages();
 	if (RTEST(coverages)) {
Index: iseq.h
===================================================================
--- iseq.h	(revision 54975)
+++ iseq.h	(revision 54976)
@@ -213,6 +213,7 @@ struct iseq_compile_data { https://github.com/ruby/ruby/blob/trunk/iseq.h#L213
     unsigned int ci_index;
     unsigned int ci_kw_index;
     const rb_compile_option_t *option;
+    st_table *ivar_cache_table;
 #if SUPPORT_JOKE
     st_table *labels_table;
 #endif
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54975)
+++ ChangeLog	(revision 54976)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed May 11 21:30:07 2016  Masaya Tarui  <tarui@r...>
+
+	* compile.c (iseq_compile_each): share InlineCache during same
+	  instance variable accesses. Reducing memory consumption,
+	  rasing cache hit rate and rasing branch prediction hit rate
+	  are expected. A part of [Bug #12274].
+
+	* iseq.h (struct iseq_compile_data): introduce instance
+	  variable IC table for sharing.
+
+	* iseq.c (prepare_iseq_build, compile_data_free):
+	  construct/destruct above table.
+
 Wed May 11 17:18:53 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* util.c (ruby_qsort): use qsort_s if available, for Microsoft

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

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