RESOLVED FIXED 67686
Optimize Node::isInShadowTree to execute in constant-time
https://bugs.webkit.org/show_bug.cgi?id=67686
Summary Optimize Node::isInShadowTree to execute in constant-time
Adam Klein
Reported 2011-09-06 17:38:50 PDT
Optimize Node::isInShadowTree to execute in constant-time
Attachments
Patch (1.27 KB, patch)
2011-09-06 17:39 PDT, Adam Klein
no flags
Adam Klein
Comment 1 2011-09-06 17:39:52 PDT
Dominic Cooney
Comment 2 2011-09-06 17:52:58 PDT
Comment on attachment 106525 [details] Patch Awesome.
Adam Klein
Comment 3 2011-09-06 17:59:03 PDT
I should ask: do y'all know of a particular test that might exercise isInShadowTree()? There are only a few callers...
Dimitri Glazkov (Google)
Comment 4 2011-09-06 19:45:02 PDT
(In reply to comment #3) > I should ask: do y'all know of a particular test that might exercise isInShadowTree()? There are only a few callers... Let's just write one.
Adam Klein
Comment 5 2011-09-07 10:44:35 PDT
(In reply to comment #4) > (In reply to comment #3) > > I should ask: do y'all know of a particular test that might exercise isInShadowTree()? There are only a few callers... > > Let's just write one. That'll require finding an entry point I understand :). The clearest usage is in HTMLLinkElement; it looks like that call was added for http://trac.webkit.org/changeset/77834, and I've run the test that patch was meant to fix (svg/dom/use-transform.svg). It passes without crashing. The other two usages are in editing/range code and in SVGTrefElement, neither of which I'm familiar enough with to exercise. Let me know if you've got something in mind...
Roland Steiner
Comment 6 2011-09-07 11:01:52 PDT
Unless someone changed SVG while I wasn't looking, this won't work for SVG, because SVG doesn't use TreeScope yet. Indeed, SVG is the only reason why we still have various functions climbing the tree to look for, e.g., the host element (Node::shadowTreeRootNode et al) rather than doing O(1) access.
Dominic Cooney
Comment 7 2011-09-07 13:33:26 PDT
You could still fast-path the in new-style shadow case as a prefix. Maybe if you’re willing to assume SVG elements don’t display non-SVG children (pretty sure I have seen that elsewhere in SVG shadow walking code) you could test !isSVGElement and predicate the fast path on that.
Dimitri Glazkov (Google)
Comment 8 2011-09-07 13:35:17 PDT
This could be a bug in existing code, but it already ignores SVG shadow roots. So I think this change doesn't make things worse. Right?
Roland Steiner
Comment 9 2011-09-07 13:39:54 PDT
(In reply to comment #8) IIRC isShadowRoot() works for both new-style shadows and SVG shadows.
Rafael Weinstein
Comment 10 2011-10-21 14:17:57 PDT
This blocks an important optimization for mutation observers
Dominic Cooney
Comment 11 2011-10-22 20:08:34 PDT
(In reply to comment #9) > IIRC isShadowRoot() works for both new-style shadows and SVG shadows. No it doesn't; look at the definition of isShadowRoot. Adam: Any reason not to R? this patch. It looks good to me.
Adam Klein
Comment 12 2011-10-24 11:39:41 PDT
(In reply to comment #11) > (In reply to comment #9) > > IIRC isShadowRoot() works for both new-style shadows and SVG shadows. > > No it doesn't; look at the definition of isShadowRoot. > > Adam: Any reason not to R? this patch. It looks good to me. Only Roland's comments, pushed back to R?.
WebKit Review Bot
Comment 13 2011-10-24 13:40:42 PDT
Comment on attachment 106525 [details] Patch Clearing flags on attachment: 106525 Committed r98275: <http://trac.webkit.org/changeset/98275>
WebKit Review Bot
Comment 14 2011-10-24 13:40:47 PDT
All reviewed patches have been landed. Closing bug.
Roland Steiner
Comment 15 2011-10-24 18:41:26 PDT
(In reply to comment #11) > (In reply to comment #9) > > IIRC isShadowRoot() works for both new-style shadows and SVG shadows. > > No it doesn't; look at the definition of isShadowRoot. That definition has changed since I made the comment! And I wonder if we haven't introduced a bug here: If I reconstruct this correctly, isInShadowTree is used in SVG at least by SVGTRefElement. This used to climb the tree looking for isShadowRoot, which used to be set for both SVG and new-style shadow roots. With the changes that isShadowRoot no longer applies for SVG and the shortcut introduced here, this is probably broken (?).
Dominic Cooney
Comment 16 2011-10-24 23:41:29 PDT
(In reply to comment #15) > (In reply to comment #11) > > (In reply to comment #9) > > > IIRC isShadowRoot() works for both new-style shadows and SVG shadows. > > > > No it doesn't; look at the definition of isShadowRoot. > > That definition has changed since I made the comment! Can you point to when it changed? I don't think it has. > And I wonder if we haven't introduced a bug here: If there a bug, it was probably introduced in this revision: <http://trac.webkit.org/changeset/84225> so maybe we should re-review that. > If I reconstruct this correctly, isInShadowTree is used in SVG at least by SVGTRefElement. This used to climb the tree looking for isShadowRoot, which used to be set for both SVG and new-style shadow roots. With the changes that isShadowRoot no longer applies for SVG and the shortcut introduced here, this is probably broken (?). Yes, it looks broken to me. (Looks like I broke it.)
Note You need to log in before you can comment on or make changes to this bug.