Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5608#discussion_r29100309
  
    --- Diff: core/src/main/scala/org/apache/spark/util/SizeEstimator.scala ---
    @@ -204,25 +204,36 @@ private[spark] object SizeEstimator extends Logging {
             }
           } else {
             // Estimate the size of a large array by sampling elements without 
replacement.
    -        var size = 0.0
    +        // To exclude the shared objects that the array elements may link, 
sample twice
    +        // and use the min one to caculate array size.
             val rand = new Random(42)
    -        val drawn = new OpenHashSet[Int](ARRAY_SAMPLE_SIZE)
    -        var numElementsDrawn = 0
    -        while (numElementsDrawn < ARRAY_SAMPLE_SIZE) {
    -          var index = 0
    -          do {
    -            index = rand.nextInt(length)
    -          } while (drawn.contains(index))
    -          drawn.add(index)
    -          val elem = ScalaRunTime.array_apply(array, 
index).asInstanceOf[AnyRef]
    -          size += SizeEstimator.estimate(elem, state.visited)
    -          numElementsDrawn += 1
    -        }
    -        state.size += ((length / (ARRAY_SAMPLE_SIZE * 1.0)) * size).toLong
    +        val drawn = new OpenHashSet[Int](2 * ARRAY_SAMPLE_SIZE)
    +        val s1 = sampleArray(array, state, rand, drawn, length)
    +        val s2 = sampleArray(array, state, rand, drawn, length)
    +        val size = math.min(s1, s2)
    +        state.size += math.max(s1, s2) + 
    +          (size * ((length - ARRAY_SAMPLE_SIZE) / 
(ARRAY_SAMPLE_SIZE))).toLong
           }
         }
       }
     
    +  private def sampleArray(array: AnyRef, state: SearchState, 
    --- End diff --
    
    Small style thing: I think the args line needs to be wrapped like the rest 
of the code (continue on new line and indent each an additional level.
    
    Also I think `if(null != object` -> `if (obj != null)`


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to