Bug 67686 - Optimize Node::isInShadowTree to execute in constant-time
Summary: Optimize Node::isInShadowTree to execute in constant-time
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Adam Klein
URL:
Keywords:
Depends on:
Blocks: 70649
  Show dependency treegraph
 
Reported: 2011-09-06 17:38 PDT by Adam Klein
Modified: 2011-10-24 23:41 PDT (History)
5 users (show)

See Also:


Attachments
Patch (1.27 KB, patch)
2011-09-06 17:39 PDT, Adam Klein
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Klein 2011-09-06 17:38:50 PDT
Optimize Node::isInShadowTree to execute in constant-time
Comment 1 Adam Klein 2011-09-06 17:39:52 PDT
Created attachment 106525 [details]
Patch
Comment 2 Dominic Cooney 2011-09-06 17:52:58 PDT
Comment on attachment 106525 [details]
Patch

Awesome.
Comment 3 Adam Klein 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...
Comment 4 Dimitri Glazkov (Google) 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.
Comment 5 Adam Klein 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...
Comment 6 Roland Steiner 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.
Comment 7 Dominic Cooney 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.
Comment 8 Dimitri Glazkov (Google) 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?
Comment 9 Roland Steiner 2011-09-07 13:39:54 PDT
(In reply to comment #8)

IIRC isShadowRoot() works for both new-style shadows and SVG shadows.
Comment 10 Rafael Weinstein 2011-10-21 14:17:57 PDT
This blocks an important optimization for mutation observers
Comment 11 Dominic Cooney 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.
Comment 12 Adam Klein 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?.
Comment 13 WebKit Review Bot 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>
Comment 14 WebKit Review Bot 2011-10-24 13:40:47 PDT
All reviewed patches have been landed.  Closing bug.
Comment 15 Roland Steiner 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 (?).
Comment 16 Dominic Cooney 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.)