[DRAFT] Prototype use of autotracking to optimize subscription behavior #2047
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR:
Subscription
anduseSelector
to try using autotracking to optimize subscription behavior and avoid executing subscriber+selector callbacks that we already know try to read state that didn't change.For background on autotracking, see:
Notes:
Subscription.ts
anduseSelector.ts
files. My plan is that if I can get this working, I would instead copy-paste the logic into separatecreateTrackedSubscription
anduseTrackedSelector
files, and that you would enable the top-level tracking behavior by passing<Provider createSubscription={createTrackedSubscription}>
. That way no one would have to pay the bundle size cost for the additional tracking logic unless they opt in, and all existinguseSelector
usage stays exactly the same.state
is an object, not a primitive. That should be the case in most apps. (Naturally, a bunch of our tests do have just a primitive like0
as the state...)useSelector
test suite all passes. Either I've done something very right, or I've done something that has no use at all :)O(n)
. It's entirely possible everything I've got here is a waste of effort because you're still calling a ton of functions.But now that I've got something that appears to at least run and pass tests, I can start doing more investigation.