aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarui <tarui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-11 12:50:38 +0000
committertarui <tarui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-11 12:50:38 +0000
commit938f9066cb0a2eca20ced81b82f23a9444b8c5d5 (patch)
tree94e8ea351d2be63dac3c3918b4005a12f6e9b79f
parentddd9f2310a476cfcd24d854466b7d0eac5216607 (diff)
downloadruby-938f9066cb0a2eca20ced81b82f23a9444b8c5d5.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog13
-rw-r--r--compile.c20
-rw-r--r--iseq.c4
-rw-r--r--iseq.h1
4 files changed, 35 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index c3858e95ba..44f0d4c6ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Wed May 11 21:30:07 2016 Masaya Tarui <tarui@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* util.c (ruby_qsort): use qsort_s if available, for Microsoft
diff --git a/compile.c b/compile.c
index 90c021a501..8dc2abdfcf 100644
--- a/compile.c
+++ b/compile.c
@@ -1542,6 +1542,19 @@ cdhash_set_label_i(VALUE key, VALUE val, void *ptr)
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_ANCHOR *ret, NODE * node, int poped)
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_ANCHOR *ret, NODE * node, int poped)
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)
RB_GC_GUARD(loader_obj);
return extra_str;
}
-
diff --git a/iseq.c b/iseq.c
index 184e56d08d..2a4d58e611 100644
--- a/iseq.c
+++ b/iseq.c
@@ -58,6 +58,8 @@ compile_data_free(struct iseq_compile_data *compile_data)
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,
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)) {
diff --git a/iseq.h b/iseq.h
index e9c97dccbe..d6b0e54820 100644
--- a/iseq.h
+++ b/iseq.h
@@ -213,6 +213,7 @@ struct iseq_compile_data {
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