Re: LocalVariablesSorter performance
Eirik Bjørsnøs (via asm Mailing List) <[email protected]> Wed, 17 Feb 2021 13:43:18 +0100
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <CA+pBWhs9cEjZiDFxvgYi7Mze=8OjS6Hzfm05AJRxXqg6zhpAZA@mail.gmail.com> |
This is a multi-part message in MIME format... ------------=_1613565814-2833-5 Content-Type: multipart/alternative; boundary="000000000000e7f68705bb879040" --000000000000e7f68705bb879040 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, In an effort to make this easier to digest, I extracted JMH benchmark into a self-contained performance demo available here: https://github.com/eirbjo/asm-lv-prepender The LocalVariablesPrepender class itself: https://github.com/eirbjo/asm-lv-prepender/blob/main/src/main/java/com/gith= ub/eirbjo/LocalVariablesDemo.java#L63 The subclass using LocalVariablesPrepender: https://github.com/eirbjo/asm-lv-prepender/blob/main/src/main/java/com/gith= ub/eirbjo/LocalVariablesDemo.java#L221 Eirik. On Wed, Feb 17, 2021 at 11:37 AM Eirik Bj=C3=B8rsn=C3=B8s <[email protected]= > wrote: > 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 LocalVariablesPrepend= er > 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 somethi= ng > similar to a LocalVariablesPrepender? > > Cheers, > Eirik. > > > --000000000000e7f68705bb879040 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><br><div>Hi,</div><div><br></div><div>In an effort to make= this easier to digest, I extracted JMH benchmark into a self-contained per= formance demo available here:</div><div><br></div><div><a href=3D"https://g= ithub.com/eirbjo/asm-lv-prepender">https://github.com/eirbjo/asm-lv-prepend= er</a><br></div><div><br></div><div>The LocalVariablesPrepender class itsel= f: <a href=3D"https://github.com/eirbjo/asm-lv-prepender/blob/main/src/main= /java/com/github/eirbjo/LocalVariablesDemo.java#L63">https://github.com/eir= bjo/asm-lv-prepender/blob/main/src/main/java/com/github/eirbjo/LocalVariabl= esDemo.java#L63</a></div><div><br></div><div>The subclass using LocalVariab= lesPrepender: <a href=3D"https://github.com/eirbjo/asm-lv-prepender/blob/ma= in/src/main/java/com/github/eirbjo/LocalVariablesDemo.java#L221">https://gi= thub.com/eirbjo/asm-lv-prepender/blob/main/src/main/java/com/github/eirbjo/= LocalVariablesDemo.java#L221</a></div><div><br></div><div>Eirik.</div></div= ><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On We= d, Feb 17, 2021 at 11:37 AM Eirik Bj=C3=B8rsn=C3=B8s <<a href=3D"mailto:= [email protected]">[email protected]</a>> wrote:<br></div><blockquote clas= s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid r= gb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div dir=3D"ltr">Hi,<div= ><br></div><div>I've been looking into the performance of LocalVariable= sSorter. This class currently only supports expanded frames, which means we= need to use the ClassReader.EXPAND_FRAMES option when reading the class.</= div><div><br></div><div>As my use case only requires prepending variables a= t the very start of methods, I don't need to support adding variables a= t arbitrary code locations. Taking this=C2=A0into consideration, I made a L= ocalVariablesPrepender 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 fram= es.</div><div><br></div><div>This allows=C2=A0LocalVariablesPrepender to be= used without ClassReader.EXPAND_FRAMES.</div><div><br></div><div>I then di= d a JMH benchmark comparing the throughput of injecting a single local vari= able (injects ICONST_M1, ISTORE x)=C2=A0 using LocalVariablesSorter to that= of my=C2=A0LocalVariablesPrepender. The class used for=C2=A0testing was Je= tty'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=A0Units<br>LocalVariableInjectors.localVa= riablesPrepender =C2=A0thrpt =C2=A0 25 =C2=A03940.191 =C2=B1 =C2=A042.010 = =C2=A0ops/s<br>LocalVariableInjectors.localVariablesSorter =C2=A0 =C2=A0 th= rpt =C2=A0 25 =C2=A02681.776 =C2=B1 175.943 =C2=A0ops/s</font><br></div><di= v><br></div><div>That's a significant performance improvement for not e= xpanding frames!</div><div><br></div><div>What would it take to rewrite Loc= alVariablesSorter to not require expanded frames? If that task is too compl= ex, then perhaps ASM should have something similar to a LocalVariablesPrepe= nder?</div><div><br></div><div>Cheers,</div><div>Eirik.</div><div><br></div= ><div><br></div></div></div> </blockquote></div> --000000000000e7f68705bb879040-- ------------=_1613565814-2833-5 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 ------------=_1613565814-2833-5--