Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-9457 Sorting improvements
  3. SPARK-9460

Avoid byte array allocation in StringPrefixComparator

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.5.0
    • SQL
    • None

    Description

      StringPrefixComparator converts the long values back to byte arrays in order to compare them. We should be able to optimize this to compare the longs directly, rather than turning the longs into byte arrays and comparing them byte by byte.

          public int compare(long aPrefix, long bPrefix) {
            // TODO: can done more efficiently
            byte[] a = Longs.toByteArray(aPrefix);
            byte[] b = Longs.toByteArray(bPrefix);
            for (int i = 0; i < 8; i++) {
              int c = UnsignedBytes.compare(a[i], b[i]);
              if (c != 0) return c;
            }
            return 0;
          }
      

      Attachments

        Issue Links

          Activity

            People

              rxin Reynold Xin
              rxin Reynold Xin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: