WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
116502
Optimized querySelector(All) when selector contains #id
https://bugs.webkit.org/show_bug.cgi?id=116502
Summary
Optimized querySelector(All) when selector contains #id
Ryosuke Niwa
Reported
2013-05-20 19:30:45 PDT
Consider implementing the same optimization as
https://chromium.googlesource.com/chromium/blink/+/1cd83d3588973a02ab15d94b1b05a28620853624
. There existed an optimization that did an element lookup for an id if the leftmost part of the selector was an id selector. Without this change, these queries would do an id lookup: querySelector("#id"), querySelector("#id.class") while these wouldn't: querySelector(".class#id"), querySelector("[name=x]#id") This change modifies the element lookup to include the latter two. More importantly, it also extends the optimization for id selectors to limit traversal of the dom-tree to the sub-tree rooted at the element with an id matching the rightmost id selector in the whole selector. For id selectors appearing left of adjacent combinators, the traversal needs to be rooted at the parent of the element with the given id. Examples: querySelector("#id span") - traversal from the id element. querySelector("#id + div span") - traversal from the parent of the id element. This fix should make this: querySelector("#id span") as fast as: getElementById("id").querySelector("span")
Attachments
Patch
(31.67 KB, patch)
2014-02-23 23:22 PST
,
Benjamin Poulain
no flags
Details
Formatted Diff
Diff
Patch
(31.11 KB, patch)
2014-03-01 11:39 PST
,
Benjamin Poulain
no flags
Details
Formatted Diff
Diff
Patch
(31.30 KB, patch)
2014-03-01 12:04 PST
,
Benjamin Poulain
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Benjamin Poulain
Comment 1
2014-02-23 23:22:09 PST
Created
attachment 225028
[details]
Patch
Andreas Kling
Comment 2
2014-02-24 14:40:05 PST
Comment on
attachment 225028
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=225028&action=review
r=me
> Source/WebCore/ChangeLog:13 > + cache, and start matching the childre from there.
Typo, children.
> Source/WebCore/dom/SelectorQuery.cpp:246 > + if (LIKELY(!rootNode.treeScope().containsMultipleElementsWithId(idToMatch))) { > + if (ContainerNode* searchRoot = rootNode.treeScope().getElementById(idToMatch)) {
It would be more efficient to do these two checks in opposite order.
> Source/WebCore/dom/SelectorQuery.cpp:417 > + CompiledSingleWithRootFilterCase:
Indentation is off here.
> Source/WebCore/dom/SelectorQuery.h:49 > - void initialize(const CSSSelectorList&); > + SelectorDataList(const CSSSelectorList&);
explicit
Benjamin Poulain
Comment 3
2014-03-01 11:39:21 PST
Created
attachment 225557
[details]
Patch
Benjamin Poulain
Comment 4
2014-03-01 12:04:11 PST
Created
attachment 225558
[details]
Patch
Benjamin Poulain
Comment 5
2014-03-01 14:05:11 PST
Committed
r164924
: <
http://trac.webkit.org/changeset/164924
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug