Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-10320

Avoid ArrayList.iterator() ExplicitColumnTracker

    XMLWordPrintableJSON

Details

    • Reviewed

    Description

      I noticed that in a profiler (sampler) run ScanQueryMatcher.setRow(...) showed up at all.
      In turns out that the expensive part is iterating over the columns in ExcplicitColumnTracker.reset(). I did some microbenchmarks and found that

      private ArrayList<X> l;
      ...
      for (int i=0; i<l.size(); i++) {
         X = l.get(i);
         ...
      }
      

      Is twice as fast as:

      private ArrayList<X> l;
      ...
      for (X : l) {
         ...
      }
      

      The indexed version asymptotically approaches the iterator version, but even at 1m entries it is still faster.
      In my tight loop scans this provides for a 5% performance improvement overall when the ExcplicitColumnTracker is used.

      Edit:

      private X[] l;
      ...
      for (int i=0; i<l.length; i++) {
         X = l[i];
         ...
      }
      

      Is even better. Apparently the JVM can even save the boundary check in each iteration.

      Attachments

        1. 10320-trunk-v4.txt
          3 kB
          Lars Hofhansl
        2. 10320-0.94-v4.txt
          3 kB
          Lars Hofhansl
        3. 10320-0.94-v3.txt
          3 kB
          Lars Hofhansl
        4. 10320-0.94-v2.txt
          1 kB
          Lars Hofhansl
        5. 10320-0.94.txt
          1 kB
          Lars Hofhansl

        Activity

          People

            larsh Lars Hofhansl
            larsh Lars Hofhansl
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: