Re: [WICG/webcomponents] Scoped Custom Element Registry: Moving elements with shadow roots between documents (#907)

> @rniwa we were able to debated this topic extensibly during the virtual F2F meeting today (you were missed there for sure). Please, read the notes. Here are my takeaways from the meeting:
> 
> 1. General consensus around a non-settable registry as you suggested. definitely seems problematic for other implementers.  the caveat here is the intersection semantics with declarative shadow root, in which case it seems we can take a similar approach to the attach shadow mechanism, a bit in the shadowRoot instance that determines whether or not the registry can be set once (probably via elementInternals). @justinfagnani will work on defining that.

Ok.

> 2. After talking about this topic for about 1hr, it seems that we started leaning toward preserving the registry from the original document. The general issue around releasing memory didn't have legs, and we discussed many potential shortcoming of trying to release the memory without exposing the GC mechanism (it seems that any work there could potentially expose the GC process to user-land).

The issue isn't about memory usage. It's an issue of a single registry being associated with multiple documents. The way WebKit's GC will work, it's highly problematic for custom elements in multiple documents to share a single custom element registry and the registry to have back reference to those custom elements for one reason or another (e.g. for parsing, upgrading, etc...).

The same issue came up during [element reflection](https://github.com/whatwg/html/issues/3515) discussion but element reflection didn't pose as much of an issue as a scoped custom element registry because scripts can't observe that the weak reference from one element to another unless they're in the same tree such that they're already accessible from scripts in some other way. With a scoped custom element registry, being able to define a new custom element and upgrading existing custom elements in shadow trees associated with the registry will require the registry to have back reference to those shadow trees as they're observable.

This is highly problematic because:
 1. It would mean that none of the shadow trees associated with a scoped custom element registry can ever be GC'ed until all shadow trees are no longer accessible from scripts, resulting in a very high memory usage.
 2. The semantics of (1) isn't implementable in WebKit as things stand today unless we re-architect how GC works with DOM objects in WebKit.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/907#issuecomment-825266773

Received on Thursday, 22 April 2021 23:31:31 UTC