RFR: 8338532: Speed up the ClassFile API MethodTypeDesc#ofDescriptor

Claes Redestad redestad at openjdk.org
Mon Aug 19 06:32:25 UTC 2024


On Fri, 16 Aug 2024 23:16:46 GMT, Shaojin Wen <duke at openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/constant/MethodTypeDescImpl.java line 125:
>> 
>>> 123:         int paramCount = 0;
>>> 124:         for (int cur = start; cur < end; ) {
>>> 125:             int len = ConstantUtils.skipOverFieldSignature(descriptor, cur, end, false);
>> 
>> I recall skipping over signatures is the main reason descriptor parsing is slow. What is the benchmark result if you allocate a buffer array like `short[] offsets = new short[Math.min(end - start, 255)]` or a `BitSet offsets = new BitSet(end - start)`?
>
> Allocating a buffer will slow down, so I used a long, with each 8 bits storing a parameter length, which can improve performance when the number of parameters is <= 8.

Since we can't have empty descriptors (`len == 0`) you could leave a 0 in the bits to signify that the parameter is too large to fit and then re-parse it in the subsequent loop below. Might simplify the control flow a bit (no need for `largeParm`, maybe possible to merge the 2nd and 3rd loops)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20611#discussion_r1720489188


More information about the core-libs-dev mailing list