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

Chen Liang liach at openjdk.org
Mon Aug 19 14:46:52 UTC 2024


On Sun, 18 Aug 2024 23:40:24 GMT, Shaojin Wen <duke at openjdk.org> wrote:

>> The current implementation of ofDescriptor puts return type and parameter types together in an ArrayList, and then splits them into return type and array of parameter types. This ArrayList creation is unnecessary, considering most descriptors only have few parameter types.
>> 
>> By splitting return type and parameter types separately and scanning the descriptor first to get the number of parameters, we can just allocate an exact, trusted array for the resulting MethodTypeDesc without copy.
>
> I added two startup process descStrings to the benchmark, and now optimized the parameter type of `Ljava/lang/Object` as follows:
> 
> ## 1. Benchmark script
> 
> git remote add wenshao git at github.com:wenshao/jdk.git
> git fetch wenshao
> 
> # baseline
> git checkout b83e2705662aa444338586713a2a7b2fa7852ba6
> make test TEST="micro:java.lang.constant.MethodTypeDescFactories.ofDescriptor"
> 
> # current
> git checkout 2405e63af284d4074056be40c550918541eead3a
> make test TEST="micro:java.lang.constant.MethodTypeDescFactories.ofDescriptor"
> 
> 
> ## 2. Performance numbers
> 
> ### 2.1 Mac Book M1 Pro
> 
> 
> -# baseline
> -Benchmark                                                                         (descString)  Mode  Cnt     Score     Error  Units
> -MethodTypeDescFactories.ofDescriptor                   (Ljava/lang/Object;Ljava/lang/String;)I  avgt    6   100.245 ?   3.888  ns/op
> -MethodTypeDescFactories.ofDescriptor                                                       ()V  avgt    6     3.762 ?   0.024  ns/op
> -MethodTypeDescFactories.ofDescriptor  (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;  avgt    6   148.798 ?  21.645  ns/op
> -MethodTypeDescFactories.ofDescriptor                                      ()Ljava/lang/Object;  avgt    6    23.890 ?   0.053  ns/op
> -MethodTypeDescFactories.ofDescriptor                  ([IJLjava/lang/String;Z)Ljava/util/List;  avgt    6   220.012 ?  63.268  ns/op
> -MethodTypeDescFactories.ofDescriptor                                     ()[Ljava/lang/String;  avgt    6    20.612 ?   0.031  ns/op
> -MethodTypeDescFactories.ofDescriptor                                                  (..IIJ)V  avgt    6   167.894 ? 153.553  ns/op
> -MethodTypeDescFactories.ofDescriptor                                         ([III.Z[B..[.[B).  avgt    6   342.610 ?   2.296  ns/op
> -MethodTypeDescFactories.ofDescriptor                                  (.....................).  avgt    6  1115.834 ?   1.067  ns/op
> 
> +# current
> +Benchmark                                                                         (descString)  Mode  Cnt     Score   Error  Units
> +MethodTypeDescFactories.ofDescriptor                   (Ljava/lang/Object;Ljava/lang/String;)I  avgt    6    48.616 ? 0.440  ns/op
> +MethodTypeDescFactories.ofDescriptor                                                       ()V  avgt    6     1.400 ? 0.004  ns/op
> +MethodTypeDescFactories.ofDescriptor  (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;  avgt    6    56.567 ? 0.101  ns/op
> +MethodTypeDescFactories.ofDescriptor...

@wenshao Can you confirm that this PR is feature frozen, that you won't add new tricks or optimizations here? Reviewers can only start reviewing if you won't bring in other changes that invalidate reviews.

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

PR Comment: https://git.openjdk.org/jdk/pull/20611#issuecomment-2296754484


More information about the core-libs-dev mailing list