-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
fix(compiler-core): change node hoisting to caching per instance #11067
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
Size ReportBundles
Usages
|
This was referenced Jun 4, 2024
/ecosystem-ci run |
This comment was marked as outdated.
This comment was marked as outdated.
/cc @huang-julien Nuxt has one test case failing here https://github.com/vuejs/ecosystem-ci/actions/runs/9365657120/job/25781312030#step:7:1279 because there are no longer |
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.
close #5256
close #9219
close #10959
Node hoisting has created various issues in the past. Most notably in some cases it can cause the first owner instance to be kept in memory forever (#5256).
The original intention of node hoisting is so that we can (1) reuse the same nodes and avoid re-creating them on each update, and (2) provide a fast path for runtime diffing.
Notably this has always been flawed because Vue's vdom algorithm requires attaching the actual DOM to the VNode, so we are cloning a copy of each hoisted node for each component instance. This is no different from caching-per-instance but leads to the memory issue described above.
With this PR:
Given the template:
Before:
After:
The generated code will look quite different after this change (see the many snapshot changes), but should be fully backwards compatible. That said this is some significant change to codegen so we are putting it in a minor to give it some alpha/beta testing time.
Other Internal Changes
hoistStatic.ts
file renamed tocacheStatic.ts
. The public optionhoistStatic
is preserved for backwards compatibility.PatchFlags.HOISTED
->PatchFlags.CACHED
stringifyStatic
logic has undergone some big changes but should remain compatible.RootNode.cached
andTransformContext.cached
are now arrays of cached nodes (null
in the case of v-memo)