<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<font size="4"><font face="monospace">Can you separate the pure JDK
implementation improvements (e.g., making j.u.c more efficient)
from the "switch to using classfile API in X" into separate
patches? </font></font><br>
<br>
<div class="moz-cite-prefix">On 4/21/2023 12:23 PM, - wrote:<br>
</div>
<blockquote type="cite" cite="mid:CABe8uE1JnT0qK__hw+kSci7BWw927p_H2ame+cXY0BJ8e7GQSw@mail.gmail.com">
<pre class="moz-quote-pre" wrap="">If there is no objection, I will submit a patch incorporating the
caching and internalName method to the Constant API, to make the
Classfile API more efficient.
Chen
On Wed, Apr 19, 2023 at 11:15 PM - <a class="moz-txt-link-rfc2396E" href="mailto:liangchenblue@gmail.com"><liangchenblue@gmail.com></a> wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">
Hello,
Since Adam has revealed that Classfile API is somewhat hampered by
performance issues and added a few patches in
<a class="moz-txt-link-freetext" href="https://github.com/openjdk/jdk/pull/12945/">https://github.com/openjdk/jdk/pull/12945/</a> that performs caching,
His patch focuses on two optimizations:
1. Speed up construction of descriptor string for MethodTypeDesc
2. Caching of ClassDesc symbol in ClassEntry (representing CONSTANT_Class_info)
Inspired by and in addition to his patches, I decided to try and see
the extent of performance impact of repeated string computation and
allocations from:
1. Creation of internal names from ClassDesc
I added a temporary API, String internalName(), to ClassDesc. This
API is forward-compatible with Valhalla, that it returns a String
suitable for a CONSTANT_Class_info.
2. Repeated descriptorString calls on MethodTypeDesc
I added a simple caching logic, much like the existing one in
java.lang.invoke.MethodType.
In addition, if the internal name and descriptor string are already
available via factory methods, the cache fields are immediately
assigned as well.
The results are promising: In jdk.classfile.Write benchmark
<a class="moz-txt-link-freetext" href="https://github.com/openjdk/jdk/blob/master/test/micro/org/openjdk/bench/jdk/classfile/Write.java">https://github.com/openjdk/jdk/blob/master/test/micro/org/openjdk/bench/jdk/classfile/Write.java</a>,
The throughput with Classfile API increased by 1/3.
Master (Patch of <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8305669">https://bugs.openjdk.org/browse/JDK-8305669</a>, since
otherwise cannot run JMH with make on Windows):
Benchmark Mode Cnt Score Error Units
Write.asmStream thrpt 5 44866.172 ± 144.049 ops/s
Write.jdkTree thrpt 5 16282.041 ± 95.782 ops/s
Write.jdkTreePrimitive thrpt 5 16352.972 ± 280.751 ops/s
New (<a class="moz-txt-link-freetext" href="https://github.com/liachmodded/jdk/commit/e33261ad197c33836d56b4b48acabc04880a780b">https://github.com/liachmodded/jdk/commit/e33261ad197c33836d56b4b48acabc04880a780b</a>)
Benchmark Mode Cnt Score Error Units
Write.asmStream thrpt 5 45695.225 ± 649.249 ops/s
Write.jdkTree thrpt 5 22786.872 ± 256.329 ops/s
Write.jdkTreePrimitive thrpt 5 22437.085 ± 397.090 ops/s
As a result, I believe it may be worth to update the Constant API to
offer ClassDesc::internalName() and method type descriptor string
caching, to enable better performance in the Classfile API.
Thanks for reading,
Chen Liang
</pre>
</blockquote>
</blockquote>
<br>
</body>
</html>