-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
feat: Add owning memos to allow memos that re-use the previous value #2139
Conversation
This seems good! Might I suggest "owning" memo or something instead of "raw"? Re: defensively taking the BorrowMut twice: It seems to me that the only situation in which that could happen would be if something during the memo function caused the memo itself to rerun, right? i.e., it would have to do something like setting a signal inside it, that would trigger an effect, that would read from the memo, which will still be marked Check at that point so will rerun? In this case That is just off the top of my head, I don't have a good test case for either of those situations. In any case it is 100% a bug in the user's code so I wouldn't worry about it too much. |
Yes! A lot better :)
Oh, sorry I didn't make it clear, I was gauging interest so I mostly copied that from the effect implementation (introduced on faa4dc4) and assumed it would be similar for Memos. From you explanation it looks like it's not, so I simplified it. The test was also mostly adapted from Also added some docs, I think it's ready for review now! |
Hi! Any feedback for this? |
So sorry for the delay. This dropped off my radar after I looked at it the last time. It looks great now! Thanks for your work. |
ty!!! |
Currently the memo function:
This means that:
This PR implements a Proof Of Concept proposing a new, more primitive, "raw memo", that allows the memo function to receive the previous value as owned, allowing it to be re-used by the memo, like effects (in fact, part of the implementation was taken from there).
"Normal" memos were changed to be implemented by using the raw memo, so there's no need to create a new reactive node. It should be backwards compatible. I haven't checked if there's any performance / binary size impact (benchmarks seems to be broken).
Unfortunately, I don't think the
create_slice
functions can take advantage of the raw memos with their current signature, but theslice!
macro should be able to.Related discussion: #1034 (reply in thread)
Main use-case: slices
The most prominent use-case is for slices[1][2][3], which can then be implemented to only clone if the value has changed. In [1], being forced to clone on every "source signal" change is actually noted as a major drawback. (1 2 3)
You can use to only clone when the value has changed:
You can even re-use the allocation: