From 07ef97df22995fc743df030e4689a59494c243d7 Mon Sep 17 00:00:00 2001 From: Sampo Kuokkanen Date: Fri, 4 Sep 2026 09:08:20 +0900 Subject: [PATCH] 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 ff831eb057 does for Mutex#synchronize. benchmark/loop_each.yml: 1.16x on arm64-darwin, 1.05x on aarch64-linux. --- array.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/array.c b/array.c index 91ddc5c60b9b10..f0d50502506d96 100644 --- a/array.c +++ b/array.c @@ -2786,8 +2786,9 @@ rb_ary_each(VALUE ary) long i; ary_verify(ary); RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length); + rb_execution_context_t *ec = GET_EC(); for (i=0; i