MINOR: Slight MetadataCache tweaks to avoid unnecessary work
Avoid tuple allocations by using `Map.update` instead of `+=`
Use `empty` instead of `apply` to avoid unnecessary array allocation
Reviewers: Rajini Sivaram Chia-Ping Tsai Andrew Choi
@@ -214,7 +214,7 @@ class MetadataCache(brokerId: Int) extends Logging {
topic: String,
partitionId: Int,
stateInfo: UpdateMetadataPartitionState): Unit = {
- val infos = partitionStates.getOrElseUpdate(topic, mutable.LongMap())
+ val infos = partitionStates.getOrElseUpdate(topic, mutable.LongMap.empty)
infos(partitionId) = stateInfo
}
@@ -319,7 +319,7 @@ class MetadataCache(brokerId: Int) extends Logging {
metadataSnapshot.partitionStates.foreach { case (topic, oldPartitionStates) =>
val copy = new mutable.LongMap[UpdateMetadataPartitionState](oldPartitionStates.size)
copy ++= oldPartitionStates
- partitionStates += (topic -> copy)
+ partitionStates(topic) = copy
}
val traceEnabled = stateChangeLogger.isTraceEnabled
