Decrease memory footprint of PromiseActorRef by ca. 30% (two ref fields)
This commit is contained in:
parent
791ec0f611
commit
d618aeb7ea
1 changed files with 8 additions and 9 deletions
|
|
@ -158,11 +158,8 @@ trait AskSupport {
|
||||||
* Akka private optimized representation of the temporary actor spawned to
|
* Akka private optimized representation of the temporary actor spawned to
|
||||||
* receive the reply to an "ask" operation.
|
* receive the reply to an "ask" operation.
|
||||||
*/
|
*/
|
||||||
private[akka] final class PromiseActorRef private (
|
private[akka] final class PromiseActorRef private (val provider: ActorRefProvider, val result: Promise[Any])
|
||||||
val provider: ActorRefProvider,
|
extends MinimalActorRef {
|
||||||
override val getParent: InternalActorRef,
|
|
||||||
val result: Promise[Any],
|
|
||||||
val deathWatch: DeathWatch) extends MinimalActorRef {
|
|
||||||
import PromiseActorRef._
|
import PromiseActorRef._
|
||||||
import AbstractPromiseActorRef.stateOffset
|
import AbstractPromiseActorRef.stateOffset
|
||||||
|
|
||||||
|
|
@ -179,7 +176,7 @@ private[akka] final class PromiseActorRef private (
|
||||||
* Stopped => stopped, path not yet created
|
* Stopped => stopped, path not yet created
|
||||||
*/
|
*/
|
||||||
@volatile
|
@volatile
|
||||||
private var _stateDoNotCallMeDirectly: AnyRef = _
|
private[this] var _stateDoNotCallMeDirectly: AnyRef = _
|
||||||
|
|
||||||
@inline
|
@inline
|
||||||
private def state: AnyRef = Unsafe.instance.getObjectVolatile(this, stateOffset)
|
private def state: AnyRef = Unsafe.instance.getObjectVolatile(this, stateOffset)
|
||||||
|
|
@ -189,9 +186,11 @@ private[akka] final class PromiseActorRef private (
|
||||||
Unsafe.instance.compareAndSwapObject(this, stateOffset, oldState, newState)
|
Unsafe.instance.compareAndSwapObject(this, stateOffset, oldState, newState)
|
||||||
|
|
||||||
@inline
|
@inline
|
||||||
private def setState(newState: AnyRef) =
|
private def setState(newState: AnyRef): Unit =
|
||||||
Unsafe.instance.putObjectVolatile(this, stateOffset, newState)
|
Unsafe.instance.putObjectVolatile(this, stateOffset, newState)
|
||||||
|
|
||||||
|
override def getParent = provider.tempContainer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract of this method:
|
* Contract of this method:
|
||||||
* Must always return the same ActorPath, which must have
|
* Must always return the same ActorPath, which must have
|
||||||
|
|
@ -252,8 +251,8 @@ private[akka] final class PromiseActorRef private (
|
||||||
case p: ActorPath ⇒
|
case p: ActorPath ⇒
|
||||||
if (updateState(p, StoppedWithPath(p))) {
|
if (updateState(p, StoppedWithPath(p))) {
|
||||||
try {
|
try {
|
||||||
deathWatch.publish(Terminated(this))
|
|
||||||
ensurePromiseCompleted()
|
ensurePromiseCompleted()
|
||||||
|
provider.deathWatch.publish(Terminated(this))
|
||||||
} finally {
|
} finally {
|
||||||
provider.unregisterTempActor(p)
|
provider.unregisterTempActor(p)
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +270,7 @@ private[akka] object PromiseActorRef {
|
||||||
|
|
||||||
def apply(provider: ActorRefProvider, timeout: Timeout): PromiseActorRef = {
|
def apply(provider: ActorRefProvider, timeout: Timeout): PromiseActorRef = {
|
||||||
val result = Promise[Any]()(provider.dispatcher)
|
val result = Promise[Any]()(provider.dispatcher)
|
||||||
val a = new PromiseActorRef(provider, provider.tempContainer, result, provider.deathWatch)
|
val a = new PromiseActorRef(provider, result)
|
||||||
val f = provider.scheduler.scheduleOnce(timeout.duration) { result.tryComplete(Left(new AskTimeoutException("Timed out"))) }
|
val f = provider.scheduler.scheduleOnce(timeout.duration) { result.tryComplete(Left(new AskTimeoutException("Timed out"))) }
|
||||||
result onComplete { _ ⇒
|
result onComplete { _ ⇒
|
||||||
try a.stop() finally f.cancel()
|
try a.stop() finally f.cancel()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue