From 16f1296afca504e7602a91df1c679f0a18a2ddf7 Mon Sep 17 00:00:00 2001 From: Maple Ong Date: Tue, 15 Mar 2022 17:09:19 -0400 Subject: [PATCH 1/2] Consider previously inlined methods leaf methods --- compile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compile.c b/compile.c index 6f2b812a1e49ba..4e7c826064a242 100644 --- a/compile.c +++ b/compile.c @@ -13069,7 +13069,8 @@ inlineable_call(CALL_DATA cd, rb_vm_insns_translator_t * translator) // A leaf method is a method with the builtin inline flag set // or a method that doesn't contain a method call - bool is_leaf_method = callee_iseq->body->builtin_inline_p || !contain_method_call; + // or a method that was previously inlined + bool is_leaf_method = callee_iseq->body->builtin_inline_p || !contain_method_call || callee_iseq->body->param.flags.inlined_iseq; // Only inline simple and leaf methods if (flags & VM_CALL_ARGS_SIMPLE && is_leaf_method) { From 30452bdd085c2333263658ab79e8a58e8a0e964a Mon Sep 17 00:00:00 2001 From: Maple Ong Date: Tue, 15 Mar 2022 17:11:33 -0400 Subject: [PATCH 2/2] Retain inline cache when copying iseqs from callee --- compile.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compile.c b/compile.c index 4e7c826064a242..1decebe3726155 100644 --- a/compile.c +++ b/compile.c @@ -13183,8 +13183,14 @@ inline_iseqs(VALUE *code, size_t pos, iseq_value_itr_t * func, void *_ctx, rb_vm char type = opnd_types[i]; switch (type) { case TS_CALLDATA: - iseq->body->ci_size++; - ops[i] = (VALUE)(((CALL_DATA)code[pos + i + 1])->ci); + if (insn_id == BIN(jump_if_cache_miss)) { + // Reuse existing cache + ops[i] = (VALUE)(((CALL_DATA)code[pos + i + 1])); + } + else { + iseq->body->ci_size++; + ops[i] = (VALUE)(((CALL_DATA)code[pos + i + 1])->ci); + } break; case TS_OFFSET: {