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

查看:30
本文介绍了有什么办法可以“提交"吗?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天全站免登陆