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?)
This commit is contained in:
Johannes Rudolph 2019-02-21 00:17:18 +01:00
parent 7fc591c182
commit f315e9693c
No known key found for this signature in database
GPG key ID: 4D293A24CCD39E19

View file

@ -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.