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

Creating uninitialized primitive arrays can boost Java performance

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Won't Fix
    • P4
    • None
    • 7
    • core-libs

    Description

      A DESCRIPTION OF THE REQUEST :
      I suggest to add

          public static native xxx[] newUninitialziedXxxArray(int size);

      set of methods to java.lang.reflect.Array for all primitive types except boolean. These methods will allow to create uninitialized primitive arrays
      when initial element values do no matter. For instance in java.util.Arrays

          public static char[] copyOf(char[] original, int newLength) {
      // char[] copy = new char[newLength];
             char[] copy = java.lang.reflect.Array.newUninitializedCharArray(newLength);
              System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
              return copy;
          }

      and many other places all over JDK.


      JUSTIFICATION :
      Zeroing arrays is expensive. This test

              long t0 = System.currentTimeMillis();
              for(int i = 0; i < 1000; i++) {
                    byte[] a = new byte[n];
              }
              System.out.println(System.currentTimeMillis() - t0);

      shows < 1ms for n = 1 and ~500 ms for n = 1000000 on my PC. Creating uninitialized arrays will boost performance.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      java.lang.reflect.Array.newUninitializedXxxArray returns xxx array with uninitialized elements.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              igerasim Ivan Gerasimov
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: