-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Conversation
[ghstack-poisoned]
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
if ($[0] !== x) { | ||
t0 = () => [x, []]; | ||
$[0] = x; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} |
There was a problem hiding this comment.
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
if ($[1] !== a || $[2] !== t2) { | ||
t3 = () => [a, x]; | ||
$[1] = a; | ||
$[2] = t2; | ||
$[3] = t3; | ||
} else { | ||
t3 = $[3]; | ||
} |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-)
ghstack-source-id: 45521370e48a7e83aaeb79cc9a14d3032bdffbe3 Pull Request resolved: #30630
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
andFinishMemoize
deps / decls are identifiers with no attached scopes (see #30603 for more complete explanation).Meta internal reviewers: see changes from this PR