Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8343559

Optimize Class.getMethod(String, Class<?>...) for methods with no-arg

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 17, 21, 23, 24
    • core-libs

      Submitting this for John Engebretson, who would be dealing with this issue.

      Class.getMethod() w/ no args is slow and commonly used. Dirty, broken, sensitivity-testing patch (attached as 8343559-jdk17.patch) makes it about 50% faster when the method is on the target class, and about 75% faster when the method is on a superclass. It likely requires more work to fit the most-specific method selection cleanly.

      Real-life impact: Spring proxies and Tomcat's expression handling often lookup zero-arg methods... for example hashcode(), toString(), getProperty1(), when not otherwise treated as a bean.

      Benchmark Mode Cnt Score Error Units

      # Base:
      GetMethodBenchmark.getHashMapToString avgt 4 363.709 ± 35.071 ns/op
      GetMethodBenchmark.getObjectToString avgt 4 60.053 ± 1.188 ns/op

      # Patched:
      GetMethodBenchmark.getHashMapToString avgt 4 96.858 ± 4.919 ns/op
      GetMethodBenchmark.getObjectToString avgt 4 36.941 ± 0.476 ns/op

        1. 8343559-jdk17.patch
          1 kB
          Aleksey Shipilev
        2. GetMethodBenchmark.java
          1 kB
          Aleksey Shipilev

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: