RFR: 8343559: Optimize Class.getMethod(String, Class<?>...) for methods with no-arg [v3]
jengebr
duke at openjdk.org
Thu Nov 7 13:48:02 UTC 2024
> This change optimizes the runtime of `Class.getMethod(String, Class<?>[])` by reducing the cost of the existing search logic. Specifically, while iterating across each Method to find a match (existing logic) it now compares parameter count before checking method name. This check is substantially faster.
>
> A benchmark and unit tests are included; benchmark results (below) show an improvement in all cases, and an especially large gain when the immediate class contains the no-arg target.
>
> Base:
>
> Benchmark Mode Cnt Score Error Units
> ClassGetMethod.getConcreteFiveArg avgt 6 94.586 ± 0.733 ns/op
> ClassGetMethod.getConcreteNoArg avgt 6 75.587 ± 11.300 ns/op
> ClassGetMethod.getIntfFiveArg avgt 6 215.794 ± 7.713 ns/op
> ClassGetMethod.getIntfNoArg avgt 6 200.418 ± 4.352 ns/op
> ClassGetMethod.getNoSuchMethod avgt 10 2207.928 ± 49.767 ns/op
> ClassGetMethod.getSuperFiveArg avgt 6 190.142 ± 1.995 ns/op
> ClassGetMethod.getSuperNoArg avgt 6 153.943 ± 7.491 ns/op
>
>
> Modified:
>
> Benchmark Mode Cnt Score Error Units
> ClassGetMethod.getConcreteFiveArg avgt 6 94.409 ± 1.642 ns/op
> ClassGetMethod.getConcreteNoArg avgt 6 77.748 ± 11.618 ns/op
> ClassGetMethod.getIntfFiveArg avgt 6 193.816 ± 4.250 ns/op
> ClassGetMethod.getIntfNoArg avgt 6 205.565 ± 9.140 ns/op
> ClassGetMethod.getNoSuchMethod avgt 10 2231.248 ± 67.711 ns/op
> ClassGetMethod.getSuperFiveArg avgt 6 169.971 ± 0.883 ns/op
> ClassGetMethod.getSuperNoArg avgt 6 129.188 ± 8.421 ns/op
jengebr has updated the pull request incrementally with one additional commit since the last revision:
Switching back to Array.equals() for parameter type comparison loop
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/21929/files
- new: https://git.openjdk.org/jdk/pull/21929/files/b0b63ecb..55f7e372
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=21929&range=02
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=21929&range=01-02
Stats: 11 lines in 1 file changed: 0 ins; 5 del; 6 mod
Patch: https://git.openjdk.org/jdk/pull/21929.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/21929/head:pull/21929
PR: https://git.openjdk.org/jdk/pull/21929
More information about the core-libs-dev
mailing list