spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srowen <...@git.apache.org>
Subject [GitHub] spark pull request #15736: [SPARK-18224] [CORE] Optimise PartitionedPairBuff...
Date Wed, 02 Nov 2016 12:19:06 GMT
Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15736#discussion_r86128297
  
    --- Diff: core/src/main/scala/org/apache/spark/util/collection/PartitionedPairBuffer.scala
---
    @@ -74,7 +74,20 @@ private[spark] class PartitionedPairBuffer[K, V](initialCapacity: Int
= 64)
       /** Iterate through the data in a given order. For this class this is not really destructive.
*/
       override def partitionedDestructiveSortedIterator(keyComparator: Option[Comparator[K]])
         : Iterator[((Int, K), V)] = {
    -    val comparator = keyComparator.map(partitionKeyComparator).getOrElse(partitionComparator)
    +    val comparator : Comparator[(Int, K)] = 
    +      if (keyComparator.isEmpty) {
    +        partitionComparator
    +    } else
    +      new Comparator[(Int, K)] {
    +        override def compare(a: (Int, K), b: (Int, K)): Int = {
    +          val partitionDiff = a._1 - b._1
    --- End diff --
    
    There are some indentation problems here and the else clause is missing a brace. I think
you can omit the type of `comparator`; no space before the colon in any event.
    
    This subtraction can overflow in theory and give the wrong answer, but the existing code
does it, so, pass on that.
    
    While optimizing, do you want to call keyComparator.get outside the class definition?
    
    There's a similar construct in PartitionedAppendOnlyMap that should be changed too. Can
this be refactored maybe?
    
    Can the method partitionKeyComparator go away? I think the whole WritablePartitionedPairCollection
object goes away after this if you care to 'inline' it too in the one refactored instance.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message