-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Use React.createContext() with observed bits #1021
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
Conversation
merge in master
also clean up unused canary values
This will allow third party apps to use these in their code
* export Context instead of just Consumer/Provider * fix error messages for removed functionality * minor displayName change
when the time is right, one need only change the BABEL_ENV for build:umd:min back to "rollup-production"
* React.forwardRef is VERY slow, on the order of 2x slower in our benchmark. So we only enable it if withRef="forwardRef" folks using withRef=true will get an error telling them to update and not rely on getWrappedInstance() but just to use the ref directly * renderCountProp is removed, as this is natively supported in React dev tools now * all usages of shallowEquals are removed for pure components, it was unnecessary. * instead of allowing passing in a custom Context consumer in props, it is now required to be passed in via connect options at declaration time.
Cool! I'll try to play around with this and get a better understanding of how it works, and see how it performs in the benchmarks. One initial question: how well does this handle the top-level state shape changing at runtime, such as dynamically adding slice reducers from code-splitting? |
How well does this handle the top-level state shape changing at runtime?
|
Awright, ran this through the benchmark suite, and... uh... it performs far worse than #995 or #1000 :
And at the moment, I can't even get it to finish the Looking at the code, I think I can see a couple possibilities why. First, this looks like it's going to call react-redux/src/components/connectAdvanced.js Lines 109 to 113 in 129ad67
react-redux/src/components/connectAdvanced.js Lines 167 to 178 in 129ad67
Second, it's doing at least a little bit extra work for each memoization check: react-redux/src/components/connectAdvanced.js Lines 209 to 218 in 129ad67
We'd have to dig further and see exactly where the bottleneck is here, I guess. @theKashey , can you clarify why that component is calling |
Ok. I have a few other options to try. The one I did is just more vanilla and passing all the tests.
So, it's complex. It's a problem.
I would try to change 2 places:
|
Actually - this is quite strange, but both examples are using flat arrays as a store. The logic behind my change not working for arrays at all. Probably slow down was driven my double render of components. PS: I could not run benchmark - package installation failing. Working only with yarn. |
Yeah, you're right about the array state shape being unusual. We ought to rework the benchmarks so they use something that looks a bit more typical, even if it's just splitting the root state into four different slices or something. |
Tried to do some perf investigations yesterday. It looks like the calculation of I think what I'd like to see for now is a new Normally we wouldn't have access to the store state in the constructor there. However, 16.5 now has |
Right now realization of observing is not quite cool - two function calls. Will try to improve it. ! What are you thinking about:
|
I made some performance computations:
|
Updated with faster key tracker, I've spiked in https://github.com./theKashey/with-known-usage, and |
facebook/react#13739 - changing PS: Actually we could use observedBits even with "old" redux. |
#1000 merged in, so I'm going to close this out. If we want to try more experiments with bitmasks, we should probably start over. |
This is extension of #1000 enhanced with "Observed Bits" specially for #1018
Key findings:
changed bits
are zero(nothing changed) context will not propagate anything. Probably this is what we want, but at least some tests are failing due it. I am adding a new prop to connect -observer
, to let "observe" any changes in state, and setting the first bit in the change always to true. Probablypure
is better fit for this. Probably we could just remove tests.observed
bits are 0, butmapStateToProps
defined - component is treated asobserver
and will not use observedBits. This is for casesstate => state
(no slice used). Probably it's better scan result in search ofstate
, but right now mappedProps are not accessible fromconnect
.state
, observed bits calculated using es5getters
. Proxy is not needed here, but it's better to double measure the speed.