LocalVariablesSorter performance

Eirik Bjørsnøs (via asm Mailing List) <[email protected]> Wed, 17 Feb 2021 11:37:03 +0100
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <CA+pBWhtoq6oYL9m1034OLwdR9NEzQnp4B0Y8D+FGqtGiSF-Bqg@mail.gmail.com>
This is a multi-part message in MIME format...

------------=_1613558239-2833-0
Content-Type: multipart/alternative; boundary="00000000000061a2bd05bb85cda9"

--00000000000061a2bd05bb85cda9
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi,

I've been looking into the performance of LocalVariablesSorter. This class
currently only supports expanded frames, which means we need to use the
ClassReader.EXPAND_FRAMES option when reading the class.

As my use case only requires prepending variables at the very start of
methods, I don't need to support adding variables at arbitrary code
locations. Taking this into consideration, I made a LocalVariablesPrepender
class which simply shifts local variables forward by the amount needed for
injecting the new variables. It also remaps all FULL frames and converts
first-frame SAME/APPEND frames into remapped FULL frames.

This allows LocalVariablesPrepender to be used without
ClassReader.EXPAND_FRAMES.

I then did a JMH benchmark comparing the throughput of injecting a single
local variable (injects ICONST_M1, ISTORE x)  using LocalVariablesSorter to
that of my LocalVariablesPrepender. The class used for testing was Jetty's
Server class.

Here are the results:

Benchmark                                        Mode  Cnt     Score
Error  Units
LocalVariableInjectors.localVariablesPrepender  thrpt   25  3940.191 =C2=B1
 42.010  ops/s
LocalVariableInjectors.localVariablesSorter     thrpt   25  2681.776 =C2=B1
175.943  ops/s

That's a significant performance improvement for not expanding frames!

What would it take to rewrite LocalVariablesSorter to not require expanded
frames? If that task is too complex, then perhaps ASM should have something
similar to a LocalVariablesPrepender?

Cheers,
Eirik.

--00000000000061a2bd05bb85cda9
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">Hi,<div><br></div><div>I&#39;ve been look=
ing into the performance of LocalVariablesSorter. This class currently only=
 supports expanded frames, which means we need to use the ClassReader.EXPAN=
D_FRAMES option when reading the class.</div><div><br></div><div>As my use =
case only requires prepending variables at the very start of methods, I don=
&#39;t need to support adding variables at arbitrary code locations. Taking=
 this=C2=A0into consideration, I made a LocalVariablesPrepender class which=
 simply shifts local variables forward by the amount needed for injecting t=
he new variables. It also remaps all FULL frames and converts first-frame S=
AME/APPEND frames into remapped FULL frames.</div><div><br></div><div>This =
allows=C2=A0LocalVariablesPrepender to be used without ClassReader.EXPAND_F=
RAMES.</div><div><br></div><div>I then did a JMH benchmark comparing the th=
roughput of injecting a single local variable (injects ICONST_M1, ISTORE x)=
=C2=A0 using LocalVariablesSorter to that of my=C2=A0LocalVariablesPrepende=
r. The class used for=C2=A0testing was Jetty&#39;s Server class.</div><div>=
<br></div><div>Here are the results:</div><div><br></div><div><font face=3D=
"monospace">Benchmark =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0Mode =C2=A0Cnt =C2=A0 =C2=A0 Score =C2=A0 =C2=A0 Error =C2=A0U=
nits<br>LocalVariableInjectors.localVariablesPrepender =C2=A0thrpt =C2=A0 2=
5 =C2=A03940.191 =C2=B1 =C2=A042.010 =C2=A0ops/s<br>LocalVariableInjectors.=
localVariablesSorter =C2=A0 =C2=A0 thrpt =C2=A0 25 =C2=A02681.776 =C2=B1 17=
5.943 =C2=A0ops/s</font><br></div><div><br></div><div>That&#39;s a signific=
ant performance improvement for not expanding frames!</div><div><br></div><=
div>What would it take to rewrite LocalVariablesSorter to not require expan=
ded frames? If that task is too complex, then perhaps ASM should have somet=
hing similar to a LocalVariablesPrepender?</div><div><br></div><div>Cheers,=
</div><div>Eirik.</div><div><br></div><div><br></div></div></div>

--00000000000061a2bd05bb85cda9--

------------=_1613558239-2833-0
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit


-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws

------------=_1613558239-2833-0--