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
refactor(core): explore approach to avoid storing LView in __ngContext__ #41293
Conversation
941bfae
to
d44a212
Compare
@@ -108,6 +108,33 @@ | |||
"packages/compiler/src/render3/view/styling_builder.ts", | |||
"packages/compiler/src/render3/view/template.ts" | |||
], | |||
[ |
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.
Please ignore these circular dependencies. If we decide to go for this approach, I'll make sure that no new circular dependencies are introduced.
@@ -123,6 +123,8 @@ function renderChildComponents(hostLView: LView, components: number[]): void { | |||
} | |||
} | |||
|
|||
const ACTIVE_LVIEWS: (LView|null)[] = []; |
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 part is potentially leaky, but IMO it'll be fine, because this is the only place where LView
s are created and destroyed and we have full control over it.
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 Looks promising, I think we should explore further. My thoughts:
- With this we are essentially getting into the business of memory management. In practice this is a ref counting scheme. The concern with ref-counting schemes is that one may forget to release memory.
- I think the key observation here is that when
LView
gets destroyed we already have to keep track of it because we need to callngDestroy
life-cycle events. This means that once destroyed there is no way to resurrect the data. Piggybacking to clean upACTIVE_LVIEWS
would be a minor cost. - There is still a concern that someone may detach
ViewRef
and than just drop it without properngDestroy
. This would create a memory leak, but a good argument can be made that it is app error since theViewRef
could be re-added and dropping it creates an unreachable references.
NOTE:
- Did not review the code in depth only looked at the main algorithm for tracking ids
- Will need a way to deal with holes in the
ACTIVE_LVIEWS
and also to ensure that we are not creating holey arrays.
d44a212
to
48ec112
Compare
**Note:** this is mostly an exploratory PR to check whether the approach actually works and to start a discussion. There's more work to be done to make it mergeable (e.g. it introduces new circular dependencies, there are no unit tests etc.). Explores adding a unique ID to each `LView` which is stored in `__ngContext__`, rather than the LView itself. This will avoid worsening memory leaks where a detached element is retained along with its `LView`. Also reworks `LContext` to store the ID of its `LView`, rather than the `LView` itself, because the `LContext` can also be stored in `__ngContext__`.
48ec112
to
9cc02cf
Compare
Closing in favor of #41358. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Note: this is mostly an exploratory PR to check whether the approach actually works and to start a discussion. There's more work to be done to make it mergeable (e.g. it introduces new circular dependencies, there are no unit tests etc.).
Explores adding a unique ID to each
LView
which is stored in__ngContext__
, rather than the LView itself. This will avoid worsening memory leaks where a detached element is retained along with itsLView
.Furthermore, it reworks
LContext
to store the ID of itsLView
, rather than theLView
itself, because theLContext
can also be stored in__ngContext__
.