Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #525 (cursor bug) by moving notify from setState callback to componentDidUpdate. #557

Merged
merged 2 commits into from
Dec 5, 2016
Merged

Fixes #525 (cursor bug) by moving notify from setState callback to componentDidUpdate. #557

merged 2 commits into from
Dec 5, 2016

Conversation

jimbolla
Copy link
Contributor

Instead of using the setState callback, doing notifyNestedSubs in componentDidUpdate seems to avoid the cursor bug (#525) without the need for the compatibility setting BS. (I swear the first time I tried this, it didn't work; I must've screwed something up. /shruggie) I'll perf test this tonight when I'm at my home PC with all my test projects. Assuming that goes well, this is a much cleaner solution. Thanks @istarkov.

This also eliminates react15CompatibilityMode stopgap setting. See: #525 (comment) for discussion.
@gaearon
Copy link
Contributor

gaearon commented Nov 30, 2016

What does the flame chart look like? When it's inside an event handler, and when it's outside an event handler (e.g. network callback).

@jimbolla
Copy link
Contributor Author

Not sure yet, but what I learned is componentDidUpdate is called before the setState callback. Unless implementing componentDidUpdate adds some unexpected perf overhead, this change should perform as good or better than the previous way. But I won't be able to test for sure I'm home.

@jimbolla
Copy link
Contributor Author

jimbolla commented Dec 1, 2016

Just ran some perf tests (react-redux-perf and redux-todomvc projects) on this change vs RC1. This change's perf is almost identical or sliiiightly better with one small tweak I just made; 10-15 ms faster total (out of 350ms) when clicking 10 times on the todo list with 10k items... basically negligible.

@jimbolla jimbolla changed the title Fixes #525 (cursor bug) by moving notify from setState callback to componentDidUpdate. [DO NOT MERGE YET - NEEDS PERF TESTING FIRST] Fixes #525 (cursor bug) by moving notify from setState callback to componentDidUpdate. Dec 1, 2016
@markerikson
Copy link
Contributor

And compared to the pre-RC1 version (ie, the "with-bug" approach)?

@jimbolla
Copy link
Contributor Author

jimbolla commented Dec 1, 2016

The test above was with compatibility=false, so that would be the "with-bug" approach. Setting it to true for my 2 test cases would let it run slightly faster in this case because none of my connected components would be affected by the stale props bug.

@gaearon
Copy link
Contributor

gaearon commented Dec 1, 2016

Can we test this with deeper nested apps? Generally “cascading setState” is slow in React but maybe this isn’t an issue here? I don’t understand the change well enough to say.

@jimbolla
Copy link
Contributor Author

jimbolla commented Dec 1, 2016

What would be a good project to use to test that?

@gaearon
Copy link
Contributor

gaearon commented Dec 1, 2016

I don't have any suggestions :-(
A fake app with boxes inside boxes, all connected?
You could use new profiling features in React 15.4.0 to get a flamechart.

@timdorr
Copy link
Member

timdorr commented Dec 5, 2016

This LGTM as-is. Sounds like (assuming I'm reading these comments right) the perf is equivalent to the 5.0 betas/alphas. We can go live with this and clean things up in 5.1 when React 16 is available (and knock out sCU!)

I suppose a further improvement would be a heuristic to determine if we even need to set the cDU, but I'm not even sure how you would go about doing that.

Any chance you ran this against React master/16? I'm curious to see how that version would perform with this change.

@timdorr timdorr merged commit 2000ff5 into reduxjs:next Dec 5, 2016
@jimbolla
Copy link
Contributor Author

jimbolla commented Dec 5, 2016

I have not tested against react master. Yesterday, I started contriving a more nested demo app and ended up shaving a ton of yaks.

@markerikson
Copy link
Contributor

Can someone summarize for me what the current state of play is for 5.0? What pieces are and are not turned on?

  • Top-down subscriptions
  • React 15/16 compat flag
  • Cursor bug

@jimbolla
Copy link
Contributor Author

jimbolla commented Dec 5, 2016

Currently, the state of next is:

  • Top-down subscriptions are on
  • Compat flag removed because not needed any more
  • Cursor bug fixed

I would like to run a perf test against React master, just in case; will do that tonight or tomorrow night.

@markerikson
Copy link
Contributor

So, net win-win, then - perf up, annoying flags down, bug fixed? Sweet!

@jimbolla
Copy link
Contributor Author

jimbolla commented Dec 7, 2016

Ran the todomvc test against react master. The difference between rc1 and latest was 314.2ms vs 322.7ms. So 8.5ms difference for 10 x 10,001 connected components. The margin is close enough that the same test probably produces slightly different results depending on the browser running it. It'll be interesting to see if there's any noticeable change once all the Fiber stuff is fully implemented in React.

@timdorr
Copy link
Member

timdorr commented Dec 7, 2016

I know @ryanflorence was building a bunch of stuff to prepare for it in Router 4.0, but scrapped it because it's hard to design for a moving target. And I'd rather not contribute to any anxiety on the React team by releasing libraries that are trying to commit to stuff that's not yet finalized and creating breakage where there shouldn't be any.

I'm guessing we'll get a way to enable Fiber in 16 and then can start playing with it and preparing for it. But no need to go crazy just yet :)

@jimbolla jimbolla deleted the connect-input-fix-alt branch December 10, 2016 21:54
albertodev7 pushed a commit to albertodev7/react-redux that referenced this pull request Dec 8, 2022
…k to componentDidUpdate. (reduxjs#557)

* Fixes reduxjs#525 (cursor bug) by moving notify from setState callback to cDU.

This also eliminates react15CompatibilityMode stopgap setting. See: reduxjs#525 (comment) for discussion.

* Optimizes perf of previous commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants