RFR: 8343559: Optimize Class.getMethod(String, Class<?>...) for methods with no-arg [v2]
jengebr
duke at openjdk.org
Wed Nov 6 17:15:06 UTC 2024
> This change optimizes the runtime of `Class.getMethod(String, Class<?>[])` in two ways:
>
> 1. 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.
> 2. While iterating (existing logic) if the requested method has no arguments, the loop terminates early after finding one match. This works because there can only be one zero-arg method with the matching name in the specific class.
>
> 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 90.866 ± 2.698 ns/op
> ClassGetMethod.getConcreteNoArg avgt 6 72.472 ± 10.225 ns/op
> ClassGetMethod.getIntfFiveArg avgt 6 198.524 ± 7.089 ns/op
> ClassGetMethod.getIntfNoArg avgt 6 191.739 ± 4.695 ns/op
> ClassGetMethod.getNoSuchMethod avgt 10 2254.308 ± 42.829 ns/op
> ClassGetMethod.getSuperFiveArg avgt 6 165.897 ± 4.370 ns/op
> ClassGetMethod.getSuperNoArg avgt 6 148.361 ± 4.573 ns/op
>
>
> Modified:
>
> Benchmark Mode Cnt Score Error Units
> ClassGetMethod.getConcreteFiveArg avgt 6 77.059 ± 2.644 ns/op
> ClassGetMethod.getConcreteNoArg avgt 6 47.666 ± 6.544 ns/op
> ClassGetMethod.getIntfFiveArg avgt 6 164.427 ± 4.356 ns/op
> ClassGetMethod.getIntfNoArg avgt 6 161.256 ± 6.832 ns/op
> ClassGetMethod.getNoSuchMethod avgt 10 2158.844 ± 43.716 ns/op
> ClassGetMethod.getSuperFiveArg avgt 6 129.047 ± 4.414 ns/op
> ClassGetMethod.getSuperNoArg avgt 6 123.728 ± 6.182 ns/op
jengebr has updated the pull request incrementally with three additional commits since the last revision:
- Optimizing filter logic by internalizing loop
- Enhancing benchmark + tests with additional 5-arg cases
- Removing no-arg optimization
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/21929/files
- new: https://git.openjdk.org/jdk/pull/21929/files/4a007cc2..b0b63ecb
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=21929&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=21929&range=00-01
Stats: 35 lines in 3 files changed: 27 ins; 4 del; 4 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