From c78cec6e732618613af304f8e4a58c97bd0e05a0 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Tue, 18 Oct 2022 03:19:36 +0700 Subject: [PATCH] removed boxing allocations inside `FSM` (#6183) (#6196) The `object.Equals` call here generated hundreds of mb in boxing allocations inside RemotePingPong - using the `EqualityComparer.Default.Equals` eliminates them. (cherry picked from commit 183ec5ae1229b2948e1b18c2e90aa75eb52f8955) Co-authored-by: Aaron Stannard --- src/core/Akka/Actor/FSM.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/Akka/Actor/FSM.cs b/src/core/Akka/Actor/FSM.cs index 8fd4c9ddd20..b817b2c6935 100644 --- a/src/core/Akka/Actor/FSM.cs +++ b/src/core/Akka/Actor/FSM.cs @@ -1262,12 +1262,14 @@ private void MakeTransition(State nextState) { Sender.Tell(nextState.Replies[i]); } - if (!_currentState.StateName.Equals(nextState.StateName) || nextState.Notifies) + + // avoid boxing + if (!EqualityComparer.Default.Equals(_currentState.StateName, nextState.StateName) || nextState.Notifies) { _nextState = nextState; HandleTransition(_currentState.StateName, nextState.StateName); Listeners.Gossip(new Transition(Self, _currentState.StateName, nextState.StateName)); - _nextState = default(State); + _nextState = default; } _currentState = nextState;