-
Notifications
You must be signed in to change notification settings - Fork 671
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
Add experimental new memoizers: autotrack and weakmap #605
Merged
Conversation
This file contains 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. |
markerikson
force-pushed
the
feature/5.0-experimental-memoizers
branch
2 times, most recently
from
April 15, 2023 02:51
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:
|
markerikson
force-pushed
the
feature/5.0-experimental-memoizers
branch
2 times, most recently
from
April 18, 2023 18:26
8c62e90
to
b644c27
Compare
markerikson
force-pushed
the
feature/5.0-experimental-memoizers
branch
2 times, most recently
from
April 27, 2023 01:19
1b61862
to
2d43549
Compare
markerikson
changed the title
Add experimental new memoizers: autotrack, weakmap, and signalis
Add experimental new memoizers: autotrack, weakmap, ~~and signalis~~
May 10, 2023
markerikson
changed the title
Add experimental new memoizers: autotrack, weakmap, ~~and signalis~~
Add experimental new memoizers: autotrack and weakmap
May 10, 2023
markerikson
force-pushed
the
feature/5.0-experimental-memoizers
branch
from
May 10, 2023 03:09
b5499d6
to
499b734
Compare
markerikson
force-pushed
the
feature/5.0-experimental-memoizers
branch
from
May 10, 2023 03:22
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:
defaultMemoize
for 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
: usesWeakMap
s to form a tree of cache lookups based on argssignalisMemoizer
: uses https://github.com/cafreeman/signalis to try to do something similar to theautotrack
approachThere'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,
autotrack
andweakMap
seem to actually work and pass tests.signalis
runs but doesn't memoize properly.autotrack
works 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.weakMap
is 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.ts
createStore
andupdate
do not work with frozen objects cafreeman/signalis#53