ruby-changes:35470
From: normal <ko1@a...>
Date: Fri, 12 Sep 2014 18:22:34 +0900 (JST)
Subject: [ruby-changes:35470] normal:r47552 (trunk): vm.c (env_alloc): inline to avoid extra zeroing
normal 2014-09-12 18:22:18 +0900 (Fri, 12 Sep 2014) New Revision: 47552 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47552 Log: vm.c (env_alloc): inline to avoid extra zeroing tiny speedup [ruby-core:64980] benchmark results: Execution time (sec) name trunk built app_lc_fizzbuzz 100.411 98.692 Speedup ratio: compare with the result of `trunk' (greater is better) name built app_lc_fizzbuzz 1.017 rb_proc_alloc changes will give more Modified files: trunk/ChangeLog trunk/vm.c Index: ChangeLog =================================================================== --- ChangeLog (revision 47551) +++ ChangeLog (revision 47552) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Sep 12 18:14:28 2014 Eric Wong <e@8...> + + * vm.c (env_alloc): inline to avoid extra zeroing + tiny speedup [ruby-core:64980] + Fri Sep 12 17:13:29 2014 Nobuyoshi Nakada <nobu@r...> * vm_method.c (rb_method_entry_make, remove_method): ditto. Index: vm.c =================================================================== --- vm.c (revision 47551) +++ vm.c (revision 47552) @@ -404,18 +404,6 @@ static const rb_data_type_t env_data_typ https://github.com/ruby/ruby/blob/trunk/vm.c#L404 NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY }; -static VALUE -env_alloc(int local_size) -{ - rb_env_t *env; - - 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); static int @@ -488,10 +476,9 @@ vm_make_env_each(const rb_thread_t *cons https://github.com/ruby/ruby/blob/trunk/vm.c#L476 } /* allocate env */ - envval = env_alloc(local_size); - GetEnvPtr(envval, env); - - env->prev_envval = penvval; + env = xmalloc(sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE))); + env->env_size = local_size + 1 + 1; + env->local_size = local_size; for (i = 0; i <= local_size; i++) { env->env[i] = envptr[-local_size + i]; @@ -504,6 +491,15 @@ vm_make_env_each(const rb_thread_t *cons https://github.com/ruby/ruby/blob/trunk/vm.c#L491 #endif } + /* be careful not to trigger GC after this */ + envval = TypedData_Wrap_Struct(rb_cEnv, &env_data_type, env); + + /* + * must happen after TypedData_Wrap_Struct to ensure penvval is markable + * in case object allocation triggers GC and clobbers penvval. + */ + env->prev_envval = penvval; + *envptr = envval; /* GC mark */ nenvptr = &env->env[i - 1]; nenvptr[1] = envval; /* frame self */ @@ -513,8 +509,10 @@ vm_make_env_each(const rb_thread_t *cons https://github.com/ruby/ruby/blob/trunk/vm.c#L509 /* as Binding */ env->block.self = cfp->self; + env->block.klass = 0; env->block.ep = cfp->ep; env->block.iseq = cfp->iseq; + env->block.proc = 0; if (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { /* TODO */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/