diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-08 19:38:22 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-08 19:38:22 +0000 |
commit | 27f9e70795e500cb934395bf17446533b8e41f76 (patch) | |
tree | 4285553eb99c6d3097a8a009ef12b93d22cbc285 | |
parent | 66d09c6d12109df49e7855207094555ec01345fb (diff) | |
download | ruby-27f9e70795e500cb934395bf17446533b8e41f76.tar.gz |
vm_core.h (rb_env_t): use flexible array
* vm_core.h (rb_env_t): use flexible array
This reduces allocations and speeds up the lambda calculus
fizzbuzz (bm_app_lc_fizzbuzz.rb) benchmark [ruby-core:64858]
* proc.c (get_local_variable_ptr): deconst to adjust for flex array
* vm.c (env_mark, env_free, env_memsize): remove check for env->env
* vm.c (env_alloc): single allocation for flex array
* vm.c (vm_make_env_each): adjust env_alloc call
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | proc.c | 2 | ||||
-rw-r--r-- | vm.c | 40 | ||||
-rw-r--r-- | vm_core.h | 2 |
4 files changed, 28 insertions, 26 deletions
@@ -1,3 +1,13 @@ +Tue Sep 9 04:36:24 2014 Eric Wong <e@80x24.org> + + * vm_core.h (rb_env_t): use flexible array + This reduces allocations and speeds up the lambda calculus + fizzbuzz (bm_app_lc_fizzbuzz.rb) benchmark [ruby-core:64858] + * proc.c (get_local_variable_ptr): deconst to adjust for flex array + * vm.c (env_mark, env_free, env_memsize): remove check for env->env + * vm.c (env_alloc): single allocation for flex array + * vm.c (vm_make_env_each): adjust env_alloc call + Mon Sep 8 16:08:22 2014 Koichi Sasada <ko1@atdot.net> * benchmark/bm_app_lc_fizzbuzz.rb: should skip output on benchmark. @@ -401,7 +401,7 @@ bind_eval(int argc, VALUE *argv, VALUE bindval) static VALUE * get_local_variable_ptr(VALUE envval, ID lid) { - const rb_env_t *env; + rb_env_t *env; do { const rb_iseq_t *iseq; @@ -354,11 +354,9 @@ env_mark(void * const ptr) if (ptr) { const rb_env_t * const env = ptr; - if (env->env) { - /* TODO: should mark more restricted range */ - RUBY_GC_INFO("env->env\n"); - rb_gc_mark_locations(env->env, env->env + env->env_size); - } + /* TODO: should mark more restricted range */ + RUBY_GC_INFO("env->env\n"); + rb_gc_mark_locations(env->env, env->env + env->env_size); RUBY_GC_INFO("env->prev_envval\n"); RUBY_MARK_UNLESS_NULL(env->prev_envval); @@ -382,8 +380,6 @@ env_free(void * const ptr) { RUBY_FREE_ENTER("env"); if (ptr) { - rb_env_t *const env = ptr; - RUBY_FREE_UNLESS_NULL(env->env); ruby_xfree(ptr); } RUBY_FREE_LEAVE("env"); @@ -395,9 +391,8 @@ env_memsize(const void *ptr) if (ptr) { const rb_env_t * const env = ptr; size_t size = sizeof(rb_env_t); - if (env->env) { - size += env->env_size * sizeof(VALUE); - } + + size += (env->env_size - 1) * sizeof(VALUE); return size; } return 0; @@ -410,15 +405,15 @@ static const rb_data_type_t env_data_type = { }; static VALUE -env_alloc(void) +env_alloc(int local_size) { - VALUE obj; rb_env_t *env; - obj = TypedData_Make_Struct(rb_cEnv, rb_env_t, &env_data_type, env); - env->env = 0; - env->prev_envval = 0; - env->block.iseq = 0; - return obj; + + env = xcalloc(1, sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE))); + env->env_size = local_size + 1 + 1; + env->local_size = local_size; + + return TypedData_Wrap_Struct(rb_cEnv, &env_data_type, env); } static VALUE check_env_value(VALUE envval); @@ -485,10 +480,6 @@ vm_make_env_each(const rb_thread_t *const th, rb_control_frame_t *const cfp, } } - /* allocate env */ - envval = env_alloc(); - GetEnvPtr(envval, env); - if (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { local_size = 2; } @@ -496,9 +487,10 @@ vm_make_env_each(const rb_thread_t *const th, rb_control_frame_t *const cfp, local_size = cfp->iseq->local_size; } - env->env_size = local_size + 1 + 1; - env->local_size = local_size; - env->env = ALLOC_N(VALUE, env->env_size); + /* allocate env */ + envval = env_alloc(local_size); + GetEnvPtr(envval, env); + env->prev_envval = penvval; for (i = 0; i <= local_size; i++) { @@ -753,11 +753,11 @@ typedef struct { GetCoreDataFromValue((obj), rb_env_t, (ptr)) typedef struct { - VALUE *env; int env_size; int local_size; VALUE prev_envval; /* for GC mark */ rb_block_t block; + VALUE env[1]; /* flexible array */ } rb_env_t; extern const rb_data_type_t ruby_binding_data_type; |