ruby-changes:72886
From: Jeremy <ko1@a...>
Date: Wed, 10 Aug 2022 14:20:01 +0900 (JST)
Subject: [ruby-changes:72886] 9363b0423a (master): Optimize duparray/expandarray -> putobject/expandarray
https://git.ruby-lang.org/ruby.git/commit/?id=9363b0423a From 9363b0423a0269272eff2e243d4b55bc8d135430 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Wed, 20 Jul 2022 15:09:20 -0700 Subject: Optimize duparray/expandarray -> putobject/expandarray There's no point in making a copy of an array just to expand it. Saves an unnecessary array allocation in the multiple assignment case, with a 35-84% improvement in affected cases in benchmark/masgn.yml. --- compile.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compile.c b/compile.c index 8879e661fe..484399abc6 100644 --- a/compile.c +++ b/compile.c @@ -3396,6 +3396,20 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal https://github.com/ruby/ruby/blob/trunk/compile.c#L3396 } } + if (IS_INSN_ID(iobj, duparray)) { + LINK_ELEMENT *next = iobj->link.next; + /* + * duparray obj + * expandarray X, 0 + * => + * putobject obj + * expandarray X, 0 + */ + if (IS_INSN(next) && IS_INSN_ID(next, expandarray)) { + INSN_OF(iobj) = BIN(putobject); + } + } + if (IS_INSN_ID(iobj, anytostring)) { LINK_ELEMENT *next = iobj->link.next; /* -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/