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

[compiler] Remove transitive memo check in validatePreserveMemo #30630

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

mofeiZ
Copy link
Contributor

@mofeiZ mofeiZ commented Aug 7, 2024

Stack from ghstack (oldest at bottom):


The original version of validatePreserveMemo tried to check that all manual memo declarations are transitively memoized. This may have been intended to stabilize useEffect by ensuring that optimized components trigger effects minimally.

This transitive memoization check only rarely affects compilation output. (Syncing this PR resulted in 12 changes out of tens of thousands of files). This is likely because many StartMemoize and FinishMemoize deps / decls are identifiers with no attached scopes (see #30603 for more complete explanation).

Meta internal reviewers: see changes from this PR

Copy link

vercel bot commented Aug 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 7, 2024 11:17pm

Comment on lines +47 to +53
if ($[0] !== x) {
t0 = () => [x, []];
$[0] = x;
$[1] = t0;
} else {
t0 = $[1];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this output correctly preserves manual memoization

Comment on lines +76 to +83
if ($[1] !== a || $[2] !== t2) {
t3 = () => [a, x];
$[1] = a;
$[2] = t2;
$[3] = t3;
} else {
t3 = $[3];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This inferred memoization also preserves manual memo

scopes: Set<ScopeId> = new Set();
prunedScopes: Set<ScopeId> = new Set();
scopeMapping = new Map();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(drive by dead code deletion)

Copy link
Contributor

@mvitousek mvitousek left a comment

Choose a reason for hiding this comment

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

nice

Copy link
Contributor

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

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

This seems reasonable. We should probably still fix up ValidateMemoizedEffectDeps and do a transitive check there, but I agree it's fine for ValidatePreserveManualMemo to be only as precise as the original memoization. Especially given the very low percentage of files impacted.

```

### Eval output
(kind: exception) mutate is not defined
Copy link
Contributor

Choose a reason for hiding this comment

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

:-)

@mofeiZ mofeiZ merged commit 30c8382 into gh/mofeiZ/18/base Aug 8, 2024
19 checks passed
mofeiZ added a commit that referenced this pull request Aug 8, 2024
ghstack-source-id: 45521370e48a7e83aaeb79cc9a14d3032bdffbe3
Pull Request resolved: #30630
@mofeiZ mofeiZ deleted the gh/mofeiZ/18/head branch August 8, 2024 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants