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

    https://github.com/apache/spark/pull/5608#discussion_r29097662
  
    --- 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)
    --- End diff --
    
    If the array size >= 400, we only have to sample 100 distinct elements from 
the array, twice.
    +    for (i <- 0 until ARRAY_SAMPLE_SIZE) {
    



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