On Mon, 6 May 2024 20:48:05 GMT, Chen Liang <li...@openjdk.org> wrote:
> A peek into TypeKind during the research for #19105 reveals that TypeKind has > a few issues: > 1. Name mismatch for `newarraycode` and `fromNewArrayCode`: Renamed both to > use "newarray code" > 2. `fromDescriptor` can throw IOOBE if the input string is empty: changed to > throw IAE and added tests. > 3. `from(Class)` can be slow due to descriptor computation: added benchmark, > will share result in next comment (as it may change with code changes). > > The first 2 changes involves API changes, and a CSR has been created. > Requesting @asotona for a review. Leaning on `TypeDescriptor.OfField::isPrimitive` presents an opportunity: override `isPrimitive` in `PrimitiveClassDescImpl` and `ReferenceClassDescImpl` to return `true` and `false` respectively: Name (type) Cnt Base Error Test Error Unit Change TypeKindBench.fromClassDescs PRIMITIVE 6 199,765 ± 3,370 205,531 ± 2,632 ns/op 0,97x (p = 0,000*) TypeKindBench.fromClassDescs REFERENCE 6 75,018 ± 1,113 25,925 ± 1,145 ns/op 2,89x (p = 0,000*) TypeKindBench.fromClasses PRIMITIVE 6 344,477 ± 46,310 366,135 ± 54,955 ns/op 0,94x (p = 0,066 ) TypeKindBench.fromClasses REFERENCE 6 23,338 ± 0,467 23,183 ± 1,357 ns/op 1,01x (p = 0,484 ) * = significant Interestingly this has a tiny regression for the primitive case - in this micro. Probably an effect of the default `descriptor.length() == 1` implementation acting as a sort of prefetch the value we'll switch on (`descriptor.charAt(0)`) down this path. Only overriding for `ReferenceClassDescImpl` is neutral, but maybe that's overfitting: Name (type) Cnt Base Error Test Error Unit Change TypeKindBench.fromClassDescs PRIMITIVE 6 199,765 ± 3,370 196,203 ± 2,469 ns/op 1,02x (p = 0,000*) TypeKindBench.fromClassDescs REFERENCE 6 75,018 ± 1,113 25,311 ± 0,138 ns/op 2,96x (p = 0,000*) TypeKindBench.fromClasses PRIMITIVE 6 344,477 ± 46,310 325,336 ± 12,203 ns/op 1,06x (p = 0,035 ) TypeKindBench.fromClasses REFERENCE 6 23,338 ± 0,467 23,462 ± 3,239 ns/op 0,99x (p = 0,805 ) * = significant ------------- PR Comment: https://git.openjdk.org/jdk/pull/19109#issuecomment-2096996186