简体   繁体   English

将对象大小存储在react-redux上

[英]Store object size on react-redux

Is any performance issue with put many items in redux-store ? redux-store放入很多物品是否存在性能问题? for example, the store is like this: 例如,商店是这样的:

{
    user:{...},
    userDetail:{},
    shoppingCart:{},
    OrderDetail:{},
    ...
}

Its keys count is almost 50 items. 它的钥匙数将近50件。

I'm using react-redux in my project to store any data (even data that are used in one section of my app and are not share). 我在我的项目中使用react-redux来存储任何数据(甚至是在我的应用程序的一个部分中使用但不共享的数据)。

It's all about the size of your data, and the way you use it. 一切都取决于数据的大小以及使用方式。

data size 资料大小

You've said you have around 50 items. 您说过您大约有50件物品。 does each item is an object? 每个项目都是对象吗? does it have 20 properties? 有20个属性吗? maybe 20,000 properties? 也许有20,000个属性? I've used redux with around 10,000 complex items (20-30 properties each) and did not experience issues, but your data / behavior might be very different 我已将redux用于大约10,000个复杂项目(每个属性20-30个属性),但没有遇到问题,但是您的数据/行为可能有很大不同

data usage 数据使用

How do you treat each change? 您如何看待每个变化? Is the effect cause a minor change, or do you change the DOM significantly? 效果是造成微小变化还是您对DOM进行了显着更改? do you use redux selectors ? 您是否使用redux 选择器

Remember that when it comes to performance, Rendering is usually much more costly than updating a data object (even a large one like redux store), so for more cases it's not your state management, it's how you use it . 请记住,在性能方面,渲染通常比更新数据对象(甚至是大型对象,如redux存储)要昂贵得多,因此在更多情况下, 它不是您的状态管理,而是您使用它的方式

However, that does not mean you may not encounter problems, so the best way to approach it would be to actually test the problematic scenarios , probably with a benchmark test . 但是,这并不意味着您可能不会遇到问题,因此解决该问题的最佳方法是实际测试有问题的方案 ,可能使用基准 测试

Generally speaking, redux considerated to be a highly-performant state-management system, considering you use it properly: 一般来说,考虑到您的正确使用,redux被认为是一种高性能的状态管理系统:

Use selectors when required, write proper reducers and splitting ui & data effectively to reducers etc. 在需要时使用选择器,编写适当的reducer并将UI和数据有效地拆分到reducer等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM