简体   繁体   English

Redux:不使用时从商店清除大型列表

[英]Redux: Clearing large lists from store when not used

Is it best practice to clear out large arrays of objects from the store when a user is not using them? 当用户不使用它们时,最好从商店中清除大型对象数组吗?

for example: 例如:

A "books list" container component loads a large array of book objects into the store under a key { books }. “书籍列表”容器组件在键{books}下将大量书籍对象加载到商店中。

When a user navigates away to another container component, lets say "movies list" that also loads a large array, this time of movies. 当用户导航到另一个容器组件时,让我们说“电影列表”也会加载大型数组,这次是电影。 Is it best to clear out the list of books to save memory / performance? 是否最好清除书籍清单以节省内存/性能? as the user may never visit the "books list" again..? 因为用户可能再也不会访问“书籍列表”..?

  • Considerations would be mobile & older desktops? 考虑因素将是移动和旧桌面?

Unless keeping it in memory turns out to cause problems during testing, I would not remove the data from the state . 除非将其保留在内存中,否则在测试期间会导致问题, 我不会从状态中删除数据

Even with a few thousand entries in the list, the memory usage should not cause you any issues, and the performance hit will be minimal if you don't eg copy the array during each state change. 即使列表中有几千个条目,内存使用也不会引起任何问题,如果您不在每次状态更改期间复制数组,性能命中率将会降至最低。

The performance hit/delay that is caused by a constant reload of the data from your backend will have a more negative impact on the user experience. 从后端持续重新加载数据导致的性能影响/延迟将对用户体验产生更大的负面影响。 You should also consider bandwidth usage, especially for mobile users. 您还应该考虑带宽使用情况,尤其是移动用户。

Once you actually face performance issues you should think about where to optimize, however clearing the state on every navigation seems like premature optimization in my eyes and the additional complexity may actually hurt you instead in the long term. 一旦你真正遇到性能问题,你应该考虑优化的位置,但是在每次导航时清除状态似乎都是我眼中的过早优化 ,而且从长远来看,额外的复杂性实际上可能会伤害到你。

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

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