简体   繁体   English

React Redux,将商店连接到1000个微型组件

[英]React Redux, connecting store to 1000 of tiny components

I have run into a performance issue with react redux, and I have been reading a bit about, and per what I ended up with, it "seems" like I am doing it all "correct". 我已经遇到了React Redux的性能问题,并且我一直在阅读有关内容,最终我发现它“似乎”就像我在做所有“正确”的事情一样。

I have a situation where I have a production line tracking system, and for each "project" there is 12 steps that it goes through. 我有一个生产线跟踪系统,对于每个“项目”,它都要经过12个步骤。 I have about 60-100 projects going on every week, split into days, easily visible on 1 view. 我每周大约有60-100个项目,分成几天,在1个视图中很容易看到。

Now the problem lies in the fact that, each of those 12 steps, are individual components that I connected up using the React Redux Connect function, which basically maps the flat store state of all the different steps, and searched out that exact step from the store, which contains data about when it was done, its status etc, and then it throws that into it as a prop, and uses it to render. 现在的问题在于,这12个步骤中的每个步骤都是我使用React Redux Connect函数连接的单个组件,该函数基本上映射了所有不同步骤的平面存储状态,并从存储,其中包含有关完成时间,状态等的数据,然后将其作为道具扔进去,并使用它进行渲染。

Now, everytime I create an update into the store of the list of steps, it obviouslly rerenders those aprox 1000 components, and checks whether or not they need to rerender, which only 1 of them then does, the one that I clicked on, lets say. 现在,每当我在步骤列表的存储区中创建一个更新时,它就会明显地重新渲染那些aprox 1000组件,并检查它们是否需要重新渲染,然后单击它们中的仅一个,然后单击说。

However, the whole computing part of looping through 1000 mapToState functions takes time, and slows down the app and makes it irresponsive. 但是,循环遍历1000个mapToState函数的整个计算部分需要时间,并且会降低应用程序的速度并使其无响应。

Is there a smarter way to go about connecting up the components to the store. 是否有更聪明的方法将组件连接到商店。

As a note, I have thought about this long before writing this, and I have also tried to map up only each project (each set of 12 steps), and have them then render pure components based on that as a parent, sending down each individual step to the child component with the data, however, I don't get any better result. 值得注意的是,我在编写此文档之前就已经考虑了很长时间,并且还尝试仅映射每个项目(每组12个步骤),然后让它们作为父对象基于此渲染纯组件,并逐个发送但是,我并没有得到更好的结果。

Thanks in advance for anyone who can help with some guidance or pushing me in the right direction. 在此先感谢您能为您提供指导或向正确的方向发展。

Vincent Rye 文森特·拉伊

I'm currently in this situation and am also looking for a definitive answer, but I'll share what I've come up with so far: 我目前处于这种情况,也正在寻找一个明确的答案,但我将分享到目前为止的建议:

For a web app to hit a target of 60fps you have a per-frame budget of 16.67ms per frame. 为了使Web应用达到60fps的目标,您需要每帧16.67ms的每帧预算。

If you have 1,000 connected components there's some amount of redux bookkeeping (like running mapStateToProps ) that will happen on every store update for every component, and to stay within a frame budget of 16.67ms you'll need that bookkeeping to happen within 0.017ms (or 17,000ns) on average. 如果您有1,000个连接的组件,则每个组件的每次商店更新都会进行一定数量的redux记账(例如运行mapStateToProps ),并且要保持在16.67ms的帧预算内,您需要在0.017ms内进行记账(或17,000ns)。

From experience, that has been hard to achieve for us. 根据经验,这对我们来说很难实现。

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

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