Skip to content

Commit 07ef97d

Browse files
Fetch the execution context once in Array#each (#18610)
rb_yield() calls GET_EC() on every element, which on arm64 is an out-of-line call to rb_current_ec() (RB_THREAD_CURRENT_EC_NOINLINE). Hoist it out of the loop and use rb_ec_yield(), as ff831eb does for Mutex#synchronize. benchmark/loop_each.yml: 1.16x on arm64-darwin, 1.05x on aarch64-linux.
1 parent 8568294 commit 07ef97d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

array.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2786,8 +2786,9 @@ rb_ary_each(VALUE ary)
27862786
long i;
27872787
ary_verify(ary);
27882788
RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
2789+
rb_execution_context_t *ec = GET_EC();
27892790
for (i=0; i<RARRAY_LEN(ary); i++) {
2790-
rb_yield(RARRAY_AREF(ary, i));
2791+
rb_ec_yield(ec, RARRAY_AREF(ary, i));
27912792
}
27922793
return ary;
27932794
}

0 commit comments

Comments
 (0)