mikemccand commented on code in PR #13936:
URL: https://github.com/apache/lucene/pull/13936#discussion_r1808871571


##########
lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java:
##########
@@ -117,7 +117,8 @@ public PriorityQueue(int maxSize, Supplier<T> 
sentinelObjectSupplier) {
    * ArrayIndexOutOfBoundsException} is thrown.
    */
   public void addAll(Collection<T> elements) {
-    if (this.size + elements.size() > this.maxSize) {
+    int size = this.size;

Review Comment:
   Could you add comments explaining that the local variable assignment is done 
on purpose for performance reasons?  We don't want a future refactoring to 
"simplify" this code and cut back to `this.size`.



##########
lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java:
##########
@@ -283,7 +293,7 @@ private final boolean upHeap(int origPos) {
     return i != origPos;
   }
 
-  private final void downHeap(int i) {
+  private void downHeap(int i, T[] heap, int size) {

Review Comment:
   Why are we removing `final` on `upHeap` and `downHeap`?  Does that somehow 
help performance?



##########
lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java:
##########
@@ -270,7 +280,7 @@ public final boolean remove(T element) {
     return false;
   }
 
-  private final boolean upHeap(int origPos) {
+  private boolean upHeap(int origPos, T[] heap) {

Review Comment:
   > Whether or not it's worth doing this kind of optimization for the observed 
gain is a tricky question
   
   We've done such optimizations in the past for very hot hotspots in Lucene, 
e.g. `readVInt`, all the carefully gen'd code for decoding `int[]` blocks in 
different bit widths, etc.  But it clearly is a tricky judgement call in each 
case...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to