> The `MethodType.genericMethodType` methods provide convenience methods for 
> certain common method types and also provide `@Stable` cache that allows for 
> constant folding. This patch enhances the more generic `methodType` methods 
> to take advantage of this cache, when possible. This allows calls like 
> `MethodType.methodType(Object.class, Object.class, ...)` to constant fold, 
> making them 50x+ faster and allocation-free.
> 
> Baseline:
> 
> Benchmark                                    Mode  Cnt   Score   Error  Units
> MethodTypeAcquire.baselineRaw                avgt   15   0.673 ? 0.017  ns/op
> MethodTypeAcquire.testGenericObject          avgt   15   0.579 ? 0.125  ns/op
> MethodTypeAcquire.testMultiPType             avgt   15  46.671 ? 1.134  ns/op
> MethodTypeAcquire.testMultiPType_Arg         avgt   15  27.019 ? 0.437  ns/op
> MethodTypeAcquire.testMultiPType_ObjectAndA  avgt   15  57.217 ? 0.505  ns/op
> MethodTypeAcquire.testMultiPType_ObjectOnly  avgt   15  57.114 ? 1.214  ns/op
> MethodTypeAcquire.testObjectObject           avgt   15  33.380 ? 1.810  ns/op
> MethodTypeAcquire.testReturnInt              avgt   15  28.043 ? 0.187  ns/op
> MethodTypeAcquire.testReturnObject           avgt   15  24.313 ? 0.074  ns/op
> MethodTypeAcquire.testReturnVoid             avgt   15  24.360 ? 0.155  ns/op
> MethodTypeAcquire.testSinglePType            avgt   15  33.572 ? 1.101  ns/op
> 
> 
> Patched:
> 
> Benchmark                                    Mode  Cnt   Score   Error  Units
> MethodTypeAcquire.baselineRaw                avgt   15   0.683 ? 0.024  ns/op
> MethodTypeAcquire.testGenericObject          avgt   15   0.547 ? 0.047  ns/op
> MethodTypeAcquire.testMultiPType             avgt   15  48.532 ? 0.982  ns/op
> MethodTypeAcquire.testMultiPType_Arg         avgt   15  31.390 ? 5.269  ns/op
> MethodTypeAcquire.testMultiPType_ObjectAndA  avgt   15  60.165 ? 2.756  ns/op
> MethodTypeAcquire.testMultiPType_ObjectOnly  avgt   15   0.599 ? 0.166  ns/op
> MethodTypeAcquire.testObjectObject           avgt   15   0.541 ? 0.045  ns/op
> MethodTypeAcquire.testReturnInt              avgt   15  28.174 ? 0.257  ns/op
> MethodTypeAcquire.testReturnObject           avgt   15   0.542 ? 0.045  ns/op
> MethodTypeAcquire.testReturnVoid             avgt   15  24.621 ? 0.202  ns/op
> MethodTypeAcquire.testSinglePType            avgt   15  33.614 ? 1.109  ns/op
> 
> 
> The cost on method types that don't match are in the noise (0-2ns/op). Even 
> on a test I constructed to act as a worst case (`testMultiPType_ObjectAndA`) 
> there's barely any appreciable cost (~3ns/op, with overlapping error).

Claes Redestad has updated the pull request incrementally with one additional 
commit since the last revision:

  Add micros using non-constant arguments to assess performance in absense of 
constant folding

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/8398/files
  - new: https://git.openjdk.java.net/jdk/pull/8398/files/6d2edc59..fcc020e6

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=8398&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=8398&range=00-01

  Stats: 18 lines in 1 file changed: 18 ins; 0 del; 0 mod
  Patch: https://git.openjdk.java.net/jdk/pull/8398.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/8398/head:pull/8398

PR: https://git.openjdk.java.net/jdk/pull/8398

Reply via email to