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

[FEAT] Adds memoizeTracked #1060

Merged
merged 1 commit into from
Mar 26, 2020
Merged

[FEAT] Adds memoizeTracked #1060

merged 1 commit into from
Mar 26, 2020

Conversation

pzuraq
Copy link
Member

@pzuraq pzuraq commented Mar 22, 2020

Adds memoizeTracked, which is meant to clean up autotracking patterns
in general by simplifying them. Also introduces beginTrackFrame and
endTrackFrame for usage within the VM.

memoizeTracked has the following signature:

function memoizeTracked<T, Args>((...args: Args) => T): (...args: Args) => T;

It essentially receives a function, and returns the same function but memoized based on tracking. If you consume a tag within that function, it will memoize based on that tag, and will only update if that tag is dirtied. Otherwise, it returns the previous result.

let count = 0;

let tag = createTag();

let counter = memoizeTracked(() => {
  count++;
  consumeTag(tag);
});

counter(); // count is 1
counter(); // count still 1
dirtyTag(tag);
counter(); // count is 2

Depends on #1063

@pzuraq pzuraq mentioned this pull request Mar 22, 2020
@pzuraq pzuraq force-pushed the feat/tracked-memoize branch 2 times, most recently from c0ab1d8 to b7696c0 Compare March 22, 2020 15:40
@pzuraq pzuraq changed the title [FEAT] Adds trackedMemoize [FEAT] Adds memoizeTracked Mar 22, 2020
Adds `memoizeTracked`, which is meant to clean up autotracking patterns
in general by simplifying them. Also introduces beginTrackFrame and
endTrackFrame for usage within the VM.

wip
@rwjblue
Copy link
Member

rwjblue commented Mar 23, 2020

Can you update the PR description to explain what the interface is and how you expect it to be used (generally speaking)?

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature being added here seems great to me!

In the future, let’s try to keep PRs a bit more focused. The rename of the validator exports should have been a separate PR as that change is unrelated to the feature added here; the additional review noise didn’t add value and makes the feature seem more complex than it is.

@rwjblue rwjblue requested a review from krisselden March 24, 2020 00:10
@pzuraq
Copy link
Member Author

pzuraq commented Mar 26, 2020

Ah, sorry about that, will definitely break things up a bit more next time!

@rwjblue rwjblue merged commit de124df into master Mar 26, 2020
@rwjblue rwjblue deleted the feat/tracked-memoize branch March 26, 2020 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants