RFR: 8331114: Further improve performance of MethodTypeDesc::descriptorString [v2]

Claes Redestad redestad at openjdk.org
Thu Apr 25 14:33:34 UTC 2024


On Thu, 25 Apr 2024 13:35:59 GMT, Chen Liang <liach at openjdk.org> wrote:

> Do we have any research on the average length of method descriptor strings? I wonder if manual pre-allocation works better (iterating all descriptor strings, allocate the sum of their sizes plus 2 (for parentheses), as descriptor strings won't be re-calculated after initial allocation.) Especially in case of user code, as many user classes have very long package names that can easily make the string much longer than the 24-char default.

I don't know of any systematic research on this, but in the code generators we have in the JDK short method signatures outweigh more complex ones by far. So if we can improve for small descriptors without regressing large ones then that's a pretty good win.

I've done some micro-benchmarking on longer descriptors and there's still a gain from the proposed patch:


MethodTypeDescFactories.ofDesc -p descString=(Lorg/openjdk/bench/java/lang/constant/MethodTypeDescFactories;Lorg/openjdk/bench/java/lang/constant/MethodTypeDescFactories;Lorg/openjdk/bench/java/lang/constant/MethodTypeDescFactories;)Lorg/openjdk/bench/java/lang/constant/MethodTypeDescFactories;

Name                                 Cnt    Base    Error     Test   Error  Unit  Change
MethodTypeDescFactories.ofDescriptor   6 442,112 ± 16,175  423,926 ± 6,245 ns/op   1,04x (p = 0,000*)
  * = significant


I'd be happy to add a variant that stresses larger descriptors.

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

PR Comment: https://git.openjdk.org/jdk/pull/18945#issuecomment-2077348963


More information about the core-libs-dev mailing list