Huang Kuan Hao created HDDS-16310:
-------------------------------------

             Summary: Avoid allocating a comparator per HeapEntry comparison in 
ListIterator
                 Key: HDDS-16310
                 URL: https://issues.apache.org/jira/browse/HDDS-16310
             Project: Apache Ozone
          Issue Type: Improvement
            Reporter: Huang Kuan Hao
            Assignee: Huang Kuan Hao


ListIterator.HeapEntry.compareTo builds a new composed Comparator on every 
call. It backs the PriorityQueue<HeapEntry> min-heap that merges the cache and 
table iterators for listStatus, so draining a listing of N entries allocates a 
fresh comparator (2-3 short-lived objects) on each of the O(N log N) 
comparisons.

Current:

  public int compareTo(HeapEntry other) {
    return Comparator.comparing(HeapEntry::getKey)
        .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
  }

Fix: hoist to a private static final Comparator<HeapEntry>, using 
thenComparingInt for the int secondary key. Behavior unchanged.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to