From f315e9693cf62873b24fdf361e73a939d64f6f6d Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Thu, 21 Feb 2019 00:17:18 +0100 Subject: [PATCH] actor: Potential systemQueuePut improvement It seems when no system messages need to be handled, systemQueuePut is mostly called with both lists being empty. In that case, we try to avoid the CAS overhead. This changes behavior at least in two regards: * no volatile memory access, so there's no barrier (but is that required?) * one less opportunity for competing threads to put a message into the queue and have that being delivered immediately, so the previous version could be seen as an extra poll (but would that be needed for anything?) --- akka-actor/src/main/scala/akka/dispatch/Mailbox.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala b/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala index 8c837d2e84..f11750bb7b 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala @@ -210,6 +210,7 @@ private[akka] abstract class Mailbox(val messageQueue: MessageQueue) Unsafe.instance.getObjectVolatile(this, AbstractMailbox.systemMessageOffset).asInstanceOf[SystemMessage]) protected final def systemQueuePut(_old: LatestFirstSystemMessageList, _new: LatestFirstSystemMessageList): Boolean = + (_old.head eq _new.head) || // Note: calling .head is not actually existing on the bytecode level as the parameters _old and _new // are SystemMessage instances hidden during compile time behind the SystemMessageList value class. // Without calling .head the parameters would be boxed in SystemMessageList wrapper.