From 655dfbc67f8fc65a1f13c40aa54106f1fbe9daa3 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Wed, 4 Mar 2020 17:11:23 +0100 Subject: [PATCH] stream: don't create AbruptTerminationException in happy case (#28686) Turned up in heavy stream materialization churn benchmark. --- .../stream/impl/fusing/ActorGraphInterpreter.scala | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/akka-stream/src/main/scala/akka/stream/impl/fusing/ActorGraphInterpreter.scala b/akka-stream/src/main/scala/akka/stream/impl/fusing/ActorGraphInterpreter.scala index aececc52e6..102330ee75 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/fusing/ActorGraphInterpreter.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/fusing/ActorGraphInterpreter.scala @@ -794,10 +794,12 @@ import scala.util.control.NonFatal newShells.map(shell => shell.toSnapshot.asInstanceOf[UninitializedInterpreter])) } - override def postStop(): Unit = { - val ex = AbruptTerminationException(self) - activeInterpreters.foreach(_.tryAbort(ex)) - activeInterpreters = Set.empty[GraphInterpreterShell] - newShells.foreach(s => if (tryInit(s)) s.tryAbort(ex)) - } + override def postStop(): Unit = + // avoid creating exception in happy case since it uses self.toString which is somewhat slow + if (activeInterpreters.nonEmpty || newShells.nonEmpty) { + val ex = AbruptTerminationException(self) + activeInterpreters.foreach(_.tryAbort(ex)) + activeInterpreters = Set.empty[GraphInterpreterShell] + newShells.foreach(s => if (tryInit(s)) s.tryAbort(ex)) + } }