spring 状态机消耗的内存

Memory comsume of spring statemachine

我曾经用spring状态机开发过一个游戏,在高峰期会创建大约5000个状态机,每个状态机大概有25个状态。但是从性能测试中,我们注意到创建了很多对象,它消耗了内存并降低了 gc 性能。 对于我的选择,有一些对象是不可变的,比如 ObjectState,它可以被所有的状态机重用。但它是为每个人创建的。

是否是spring状态机的性能问题?还是我用错了?

10: 104192  10002432    org.springframework.statemachine.state.ObjectState
15: 208398  6668736 org.springframework.statemachine.support.OrderedCompositeItem
17: 397839  6365424 org.springframework.core.annotation.AnnotationAwareOrderComparator
18: 189440  6062080 org.springframework.statemachine.listener.OrderedComposite
26: 71040   4546560 org.springframework.statemachine.trigger.TimerTrigger
27: 89984   4319232 org.springframework.statemachine.transition.DefaultExternalTransition
30: 203648  3258368 org.springframework.statemachine.action.CompositeActionListener
42: 71040   1704960 org.springframework.statemachine.support.DefaultStateMachineExecutor
45: 104192  1667072 org.springframework.statemachine.support.AbstractStateMachine
46: 104192  1667072 org.springframework.statemachine.state.CompositeStateListener

没错,这些是为每台机器创建的。如果这些可以被创建一次然后以某种方式在其他实例之间共享,这是一个有趣的想法,因为它肯定会减少垃圾。您介意为此创建一个 gh 问题吗?