On Sun, 7 Jan 2024 18:16:05 GMT, Chen Liang <li...@openjdk.org> wrote:

>> Original code has been significant in profiler.
>> 
>> 
>> MethodTypeDesc desc = MethodTypeDesc.of(toClassDesc(returnType),
>>                     
>> Arrays.stream(parameterTypes).map(ProxyGenerator::toClassDesc).toArray(ClassDesc[]::new));
>> 
>> 
>> 1. each `toClassDesc` builds `descriptorString` and parses/validates it 
>> while constructing `ClassDesc`
>> 2. `Arrays.stream(...).map(...).toArray(...)` allocates an array
>> 3. `MethodTypeDesc.of(...)` clones the array and iterates params to check 
>> for void
>> 4. `desc.descriptorString()` then finally use the `StringJoiner` 
>> 
>> Optimized code only joins `descriptorString`, no validations, no streaming, 
>> no arrays, no cloning.
>> 
>> 
>> I suggest this patch as this code is considered as performance critical.
>> However we can go through `ClassDesc` and `MethodTypeDesc` if not 
>> performance critical or if the conversions would be optimized.
>> 
>> For example better (trusted) paths from `MethodType` to 
>> `MethodTypeDescriptor` and from `Class` to `ClassDesc`, avoiding at least 
>> validations.
>
> Turns out your approach to avoid MTD here is apparently useless; 
> `MethodTypeDesc` is still created for initializing the local tracker 
> `topLocal` in `DirectCodeBuilder`. In addition, `StackMapDecoder` also uses 
> `methodTypeSymbol` to compute the initial frame.
> 
> IMO we should just stay with MTD; the descriptor breakdown happens too often 
> and, from previous benchmarks, descriptor breakdown is actually slow (which 
> gives CF API a small edge over ASM here). But we can still replace the 
> `parameterList()` iteration with index-based iteration to avoid array copies.

Right, there are still so many conversions.
I'll revert the custom code to simplify further optimizations.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17121#discussion_r1444690465

Reply via email to