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

[DRAFT] Prototype use of autotracking to optimize subscription behavior #2047

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

markerikson
Copy link
Contributor

@markerikson markerikson commented Jun 26, 2023

This PR:

  • Has a totally WIP prototype POC reworking of Subscription and useSelector 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:

  • This branch currently rewrites the existing Subscription.ts and useSelector.ts files. My plan is that if I can get this working, I would instead copy-paste the logic into separate createTrackedSubscription and useTrackedSelector 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 existing useSelector usage stays exactly the same.
  • It assumes that the root 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 like 0 as the state...)
  • The existing useSelector test suite all passes. Either I've done something very right, or I've done something that has no use at all :)
  • I have no idea what the performance cost is of any of this right now, or how it behaves in a full real-world-sized state tree + thousands of components. I'll have to look into that next. I know that this is doing a bunch of additional work at the top level to reconcile the new state tree vs the old one and mark fields as dirty. It's also having to do work to track dependencies and recalculate changed revisions, and those are still 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.

@markerikson markerikson marked this pull request as draft June 26, 2023 19:22
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 26, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bbf7a4f:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration

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.

1 participant