-
Notifications
You must be signed in to change notification settings - Fork 666
Add experimental new memoizers: autotrack and weakmap #605
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Aaaand the build is totally busted due to some Reselect -> RTK -> Reselect dependency thing. Will worry about that later. |
9467048 to
27c412b
Compare
|
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 41959cd:
|
8c62e90 to
b644c27
Compare
1b61862 to
2d43549
Compare
b5499d6 to
499b734
Compare
c7abf78 to
7efdeea
Compare
|
Updates since the original PR creation:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
defaultMemoizefor perf atmmemoize()there now)autotrackMemoizer: uses Proxies and an "autotracking" implementation to determine exactly which fields are accessed in a selector, and only recalculate when those fields get changedweakMapMemoizer: usesWeakMaps to form a tree of cache lookups based on argssignalisMemoizer: uses https://github.com/cafreeman/signalis to try to do something similar to theautotrackapproachThere's a good chance that these could go into v4.x, but I'm putting them in a 5.x-based build branch for now.
Status and Tradeoffs
Currently,
autotrackandweakMapseem to actually work and pass tests.signalisruns but doesn't memoize properly.autotrackworks well! I can confirm that if you do something liketodos => todos.map(t => t.id), and then flipt.completed, it will not recalculate. However, it also is definitely slower thandefaultMemoize. The question is whether the slowness is enough to matter in practice. On the flip side, the fact that it can recalculate a lot less often in some cases means that there'd be fewer re-renders.weakMapis closer in speed todefaultMemoize. Haven't done significant testing on it yet. Seems like there's some amount of multi-size behavior by default, but haven't figured out how that grows over time or gets GC'd.Resources / inspiration / places I swiped code from:
ReactCache.tscreateStoreandupdatedo not work with frozen objects cafreeman/signalis#53