Ngone51 commented on code in PR #46705:
URL: https://github.com/apache/spark/pull/46705#discussion_r1612862173
##########
core/src/main/scala/org/apache/spark/executor/TaskMetrics.scala:
##########
@@ -328,16 +328,15 @@ private[spark] object TaskMetrics extends Logging {
*/
def fromAccumulators(accums: Seq[AccumulatorV2[_, _]]): TaskMetrics = {
val tm = new TaskMetrics
- for (acc <- accums) {
+ val (innerAccums, externalAccums) = accums.
+ partition(t => t.name.isDefined && tm.nameToAccums.contains(t.name.get))
+ for (acc <- innerAccums) {
val name = acc.name
- if (name.isDefined && tm.nameToAccums.contains(name.get)) {
- val tmAcc = tm.nameToAccums(name.get).asInstanceOf[AccumulatorV2[Any,
Any]]
- tmAcc.metadata = acc.metadata
- tmAcc.merge(acc.asInstanceOf[AccumulatorV2[Any, Any]])
- } else {
- tm._externalAccums.add(acc)
- }
+ val tmAcc = tm.nameToAccums(name.get).asInstanceOf[AccumulatorV2[Any,
Any]]
+ tmAcc.metadata = acc.metadata
+ tmAcc.merge(acc.asInstanceOf[AccumulatorV2[Any, Any]])
}
+ tm._externalAccums.addAll(externalAccums.asJava)
Review Comment:
So this change reduce the copy times from `externalAccums#size` to one?
##########
core/src/main/scala/org/apache/spark/executor/TaskMetrics.scala:
##########
@@ -328,16 +328,15 @@ private[spark] object TaskMetrics extends Logging {
*/
def fromAccumulators(accums: Seq[AccumulatorV2[_, _]]): TaskMetrics = {
val tm = new TaskMetrics
- for (acc <- accums) {
+ val (innerAccums, externalAccums) = accums.
+ partition(t => t.name.isDefined && tm.nameToAccums.contains(t.name.get))
+ for (acc <- innerAccums) {
val name = acc.name
- if (name.isDefined && tm.nameToAccums.contains(name.get)) {
- val tmAcc = tm.nameToAccums(name.get).asInstanceOf[AccumulatorV2[Any,
Any]]
- tmAcc.metadata = acc.metadata
- tmAcc.merge(acc.asInstanceOf[AccumulatorV2[Any, Any]])
- } else {
- tm._externalAccums.add(acc)
- }
+ val tmAcc = tm.nameToAccums(name.get).asInstanceOf[AccumulatorV2[Any,
Any]]
+ tmAcc.metadata = acc.metadata
+ tmAcc.merge(acc.asInstanceOf[AccumulatorV2[Any, Any]])
}
+ tm._externalAccums.addAll(externalAccums.asJava)
Review Comment:
So this change reduces the copy times from `externalAccums#size` to one?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]