zhengruifeng edited a comment on pull request #30468:
URL: https://github.com/apache/spark/pull/30468#issuecomment-732096836


   Finally, I found that 
[Guava.Ordering](https://github.com/apache/spark/pull/30468/commits/7dd2b919b7149e5064cc1bd90100db52feb6cba2)
 seems much more efficient than `BoundedPriorityQueue`. (see [Selecting top k 
items from a list efficiently in Java / 
Groovy](https://www.michaelpollmeier.com/selecting-top-k-items-from-a-list-efficiently-in-java-groovy)).
   
   ```
     /** select top indices based on values. */
     private[recommendation] class TopSelector(val values: Array[Float]) {
       import scala.collection.JavaConverters._
   
       private val indexOrdering = new GuavaOrdering[Int] {
         override def compare(left: Int, right: Int): Int = {
           Ordering[Float].compare(values(left), values(right))
         }
       }
   
       def selectTopKIndices(iterator: Iterator[Int], k: Int): Array[Int] = {
         indexOrdering.greatestOf(iterator.asJava, k).asScala.toArray
       }
     }
   ```
   Compared to `BoundedPriorityQueue`, we do not need to create many object 
references like `Tuple2` here.
   
   
![als_gemv_array_jobs_2020_11_23_16_44_39](https://user-images.githubusercontent.com/7322292/99956156-81d32000-2dc0-11eb-9684-43685ef3a7b0.png)
   
   
![als_gemv_array_exe_2020_11_23_16_44_15](https://user-images.githubusercontent.com/7322292/99956172-8a2b5b00-2dc0-11eb-8d13-21a81d8b3f4d.png)
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to