MethodHandles.arrayConstructor can be cached

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P4
    • None
    • Affects Version/s: 21
    • Component/s: core-libs

      MethodHandles.arrayConstructor calls asType on a trusted method handle that's known to return instances of the array type. We can swap the asType() call with viewAsType(type, false) for better creation performance. In addition, it can probably be cached like other array element accessors; in JDK 20 its creation performance is 61ns/op (tested with String[]), while the cached int[] element accessors are created at 1.5ms/op.

            Assignee:
            Chen Liang
            Reporter:
            Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: