Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to "commit" the state in Redux to free memory?

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.

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.

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.

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.

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

Thank you in advance!

like image 491
Crisu83 Avatar asked Feb 25 '16 12:02

Crisu83


People also ask

What's the maximum memory size of the Redux store?

This Data can be about 70-80 KB but I think average size of each user will be 30-40 kb. This data is modified with combined of 5-6 reducers and 30-50 actions.

How do I edit Redux state?

Step 1. Click Dispatcher. Step 2: Now provide which 'action type' you want to modify. Step 3: Create a payload object & modify the state which you want to modify.

Where is Redux data stored?

The state in Redux is stored in memory. This means that, if you refresh the page the state gets wiped out. The state in redux is just a variable that persists in memory because it is referenced by all redux functions.


1 Answers

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.

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.

like image 146
markerikson Avatar answered Dec 30 '22 11:12

markerikson