有什么办法可以“提交”吗? Redux中的状态释放内存? [英] Is there any way to "commit" the state in Redux to free memory?

查看:98
本文介绍了有什么办法可以“提交”吗? Redux中的状态释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发实时多人游戏,并且在服务器和客户端存储应用程序的状态。

I'm working on a real-time multiplayer game and I use Redux on both the server and the client to store the state of the application.

但是,由于我的游戏是实时的,因此分派到商店中的动作数量明显高于通常的应用程序。我怀疑这就是为什么Redux使用大量内存的原因。

However, the amount of actions dispatched into the store is significantly higher than in an usual application because my game is real-time. I suspect that this is why Redux is using a lot of memory.

据我了解,Redux将调度到存储中的所有操作存储在内存中,以便能够执行其操作。 时间旅行。我还注意到 Redux DevTools 允许您提交状态。

To my understanding Redux stores all actions dispatched into a store in memory in order to be able to do its "time traveling". I also noticed that the Redux DevTools allows you to commit the state.

我想做的是提交应用程序,例如每10秒保存一次内存。无论如何,我都不需要在应用程序中返回超过10秒的时间,因此即使出于调试目的,似乎也不需要存储所有操作。

What I would like to do is commit the application e.g. every 10 seconds to save memory. I never have the need to go back more than 10 seconds in my application anyway so storing all actions seems unnecessary, even for debugging purposes.

Redux是否支持此功能?如果不是,是否有任何方法可以实现此行为?

Does Redux support this? If not, is there any way to achieve this behavior?

预先感谢您!

推荐答案

请注意,尽管Redux DevTools确实存储了启用时间旅行调试功能的动作历史记录,但是Redux本身并没有-它仅保留对当前状态的引用。由于呈现了动作列表和存储内容,DevTools也有一些额外的开销。

Note that while the Redux DevTools do store the history of actions to enable the time-travel debugging feature, Redux itself does not - it only keeps a reference to the current state. The DevTools also have some additional overhead due to rendering the list of actions and store contents.

此外:您还说Redux正在使用大量内存 ? Redux使用的唯一内存是表示存储状态所需的任何内存。除非您有一些特定的基准实际上显示内存问题,否则我不会将其视为有意义的问题。

Beyond that: what makes you say that Redux is "using a lot of memory"? The only memory that Redux uses is whatever is needed to represent the store state. Unless you have some particular benchmarks that actually show memory problems, I wouldn't see it as a meaningful concern.

这篇关于有什么办法可以“提交”吗? Redux中的状态释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆