Currently we set it when a node is inserted into a tree. But it lets all nodes behind shadow to have NodeRareData. That means it no longer "rare". In reality, NodeRareData::m_treeScope is a kind of a cash. So we don't maintain it eagerly. It can be lazily retrieved. This is an alternative of Bug 59816 which aimed to make TreeScope management saner and performant.
Created attachment 134738 [details] WIP
Comment on attachment 134738 [details] WIP View in context: https://bugs.webkit.org/attachment.cgi?id=134738&action=review > Source/WebCore/dom/Node.cpp:446 > +TreeScope* Node::treeScope(TreeScopeStoreCacheType scoreCache) const If we took this approach I think you'd need some kind of DirtyTreeScope bit field in node otherwise you're going to cause rare data on every node we call treeScope() on, ex. during event dispatch, and you're also going to introduce this tree walk for treeScope() into all existing pages even ones that don't use Shadow DOM so treeScope gets much slower.
(In reply to comment #2) > If we took this approach I think you'd need some kind of DirtyTreeScope bit field in node otherwise you're going to cause rare data on every node we call treeScope() on, ex. during event dispatch, and you're also going to introduce this tree walk for treeScope() into all existing pages even ones that don't use Shadow DOM so treeScope gets much slower. Yes, this approach looks inferior than replacing document pointer. We need to inspect each treeScope() call to decide which (slow-clean or fast-caching) we should use. That isn't what we want. This bug was just a result of exploration for attacking slow-treeScope problem.
Since r138735 m_treeScope is in Node. So I believe this is fixed.
It's probably better to close this with WONTFIX since this bug no longer applies to ToT WebKit.