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)) + } }