- Notifications
You must be signed in to change notification settings - Fork666
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Aaaand the build is totally busted due to some Reselect -> RTK -> Reselect dependency thing. Will worry about that later. |
9467048 to27c412bComparecodesandbox-cibot commentedApr 18, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This pull request is automatically built and testable inCodeSandbox. To see build info of the built libraries, clickhere or the icon next to each commit SHA. Latest deployment of this branch, based on commit41959cd:
|
8c62e90 tob644c27Compare1b61862 to2d43549Compareb5499d6 to499b734Comparec7abf78 to7efdeeaCompareUpdates since the original PR creation:
|
Uh oh!
There was an error while loading.Please reload this page.
This PR:
defaultMemoizefor perf atmmemoize()there now)autotrackMemoizer: uses Proxies and an "autotracking" implementation to determineexactly 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: useshttps://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 willnot 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