Github user JoshRosen commented on a diff in the pull request: https://github.com/apache/spark/pull/1499#discussion_r15495220 --- Diff: core/src/main/scala/org/apache/spark/storage/ShuffleBlockManager.scala --- @@ -91,6 +97,20 @@ class ShuffleBlockManager(blockManager: BlockManager) extends Logging { private val metadataCleaner = new MetadataCleaner(MetadataCleanerType.SHUFFLE_BLOCK_MANAGER, this.cleanup, conf) + /** + * Register a completed map without getting a ShuffleWriterGroup. Used by sort-based shuffle + * because it just writes a single file by itself. + */ + def addCompletedMap(shuffleId: Int, mapId: Int, numBuckets: Int): Unit = { + shuffleStates.putIfAbsent(shuffleId, new ShuffleState(numBuckets)) --- End diff -- In both TimeStampedHashMap and scala.collection.concurrent.Map, `putIfAbsent`'s value is call-by-value, not call-by-name: ``` def putIfAbsent(key: A, value: B): Option[B] ``` As a result, this code will end up calling `new ShuffleState(numBuckets)` on every completed map task. ShuffleState looks moderately expensive to construct since it contains a bunch of queues, etc. It would be more efficient to extend TimeStampedHashMap with a `getOrElseUpdate` method whose `default` argument is call-by-name so that we don't end up constructing and discarding so many ShuffleStates.
--- 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. ---