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

    https://github.com/apache/spark/pull/1195#discussion_r14309466
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/receiver/BlockGenerator.scala
 ---
    @@ -134,9 +168,26 @@ private[streaming] class BlockGenerator(
         logError(message, t)
         listener.onError(message, t)
       }
    -  
    +
       private def pushBlock(block: Block) {
         listener.onPushBlock(block.id, block.buffer)
    +
    +    var callbackBufferOpt: Option[ArrayBuffer[Callback]] = None
    +    // Remove the buffer from the callbacks map. This must be synchronized 
to ensure no one else
    +    // is editing the buffer or the map at that time.
    +    synchronized {
    +      callbackBufferOpt = Option(callbacks.remove(block.id))
    +    }
    +
    +    // Call the callbacks
    +    callbackBufferOpt match {
    +      case Some(callbackBuffer) =>
    +        callbackBuffer.map(callback => {
    --- End diff --
    
    AFAIK `foreach` doesn't need to collect the results of the closure into a 
new object, so you save a little in memory allocation. (For an Option that 
means not having to allocate a new Option, for a list it means not needing a 
completely new list with the transformed objects.)
    
    Or, in other words: `map()` returns a `Seq[T]`, `foreach()` returns `Unit`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to