pixelpaint icon indicating copy to clipboard operation
pixelpaint copied to clipboard

Add a simple but reasonably fast Redux version

Open gaearon opened this issue 9 years ago • 8 comments

It's less efficient than V3 but also way simpler. Relies on memoization of props (which is something you want to do in intensive apps).

This gives me ~20ms for going through 32K nodes which IMO is good enough for most real apps.

I used [email protected] because it is the latest stable version and the one I optimized. I haven't participated in the 5.x effort and can't say if it is optimal for this scenario (but it does seem 1.5-2x slower).

gaearon avatar Dec 09 '16 20:12 gaearon

Very nice. Would love to hear @jimbolla 's thoughts on the perf difference between 4.4.6 and 5.0.

markerikson avatar Dec 09 '16 20:12 markerikson

@markerikson I'm not sure what I'm looking at here.

jimbolla avatar Dec 09 '16 23:12 jimbolla

@jimbolla : per Dan's comments at https://www.reddit.com/r/reactjs/comments/5hf4d4/an_artificial_example_where_mobx_really_shines/ and https://twitter.com/dan_abramov/status/807320728706150400 , the original version of this benchmark apparently was already using react-redux@next. Dan's new variation of this benchmark switched back to 4.4.6, and that plus the use of mapState factories made things faster.

Basically I'm curious if v5 actually makes things better or worse overall in variations on this benchmark.

markerikson avatar Dec 10 '16 00:12 markerikson

Thanks @gaearon for joining in!

Seems scripting takes about 20% of the run time, so it’s much better than V1 and V2.

screen shot 2016-12-10 at 10 14 41

@markerikson The reason I use react-redux@next is because of this line in master: the !this.doStatePropsDependOnOwnProps which says that if the computed state depended on own props, don’t early return.

This causes 32,768 components to go through React’s update cycle and end up with shouldComponentUpdate. This takes up a significant amount of time. By memoizing (using the initialProps instead of ownProps), this enables early return which is where perf gain came from. Somehow, it is slower in v5.

dtinth avatar Dec 10 '16 03:12 dtinth

I think v5 might be faster for general case but slower for a stress test like this. Not sure.

gaearon avatar Dec 10 '16 03:12 gaearon

The pattern where mapStateToProps = (initialState, intialProps) => (justState) => results is the known case where v4 is faster than v5. v4's alogrith works really well for that usage. v5 benefits more from the mapStateToProps = (state, props) => results usage.

jimbolla avatar Dec 10 '16 14:12 jimbolla

Coming across the topic more than a year later - are the findings still the status quo? An update would be great! :)

loopmode avatar May 29 '18 18:05 loopmode

I don't think anything has meaningfully changed.... yet. You may want to look at the React-Redux roadmap I put up for discussion in https://github.com/reduxjs/react-redux/issues/950 .

markerikson avatar May 29 '18 18:05 markerikson