Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(949)

Issue 2820013002: Separate the id fast path in SelectorQuery. (Closed)

Created:
3 years, 8 months ago by esprehn
Modified:
3 years, 8 months ago
Reviewers:
meade_UTC10, dglazkov, rune
CC:
blink-reviews, blink-reviews-dom_chromium.org, chromium-reviews, dglazkov+blink, eae+blinkwatch, rwlbuis, sof
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Separate the id fast path in SelectorQuery. This allows us to use the id to limit the search in *All queries like document.querySelectorAll("#scope .foo") where previously we'd scan the entire document looking for .foo, now we'll first use the id map to find #scope. This also means we'll now use the class fast path for queries like document.querySelector(".foo .bar") where previously we disabled the class fast path entirely just in case there was an id selector somewhere past the class selector (ex. #foo .bar). Finally I cached the id information so we don't need to scan the selector each time. A future patch will be able to use this data and new id specific path to support using the id map for elements inside a ShadowRoot that is not attached to the tree making queries like querySelector("#foo") O(1) when the host scope is disconnected. On an example page like Wikpedia cats (https://en.wikipedia.org/wiki/Cat) with 9800 elements this yields a 25% improvement in class queries that can now take the class fast path that needed to scan the entire document, and up to a 90% improvement in queries that can now take the id fast path to either quickly abort when the id is not present, or limit the scope to a small number of elements: ex. var t = performance.now(); document.querySelectorAll("#catlinks .mw-normal-catlinks"); performance.now() - t; goes from taking 0.32ms to taking 0.03ms. Or simulating an doing many queries: var t = performance.now(); for (let i = 0; i < 100; ++i) { document.querySelectorAll("#catlinks .mw-normal-catlinks"); } performance.now() - t; Goes from taking 15ms to taking 0.24ms. This improvement brings us within 20% of the speed of Safari on all queries containing ids. Bindings and NodeList TraceWrapper overhead are now the primary issues. (We already beat Firefox on all these benchmarks, and they don't handle ids anywhere except in the rightmost subs selector, for example the above benchmarks take 0.5ms and 25ms respectively.) Note: These numbers were all taken on a 2013 Mac Pro trashcan. BUG=703900 Review-Url: https://codereview.chromium.org/2820013002 Cr-Commit-Position: refs/heads/master@{#464861} Committed: https://chromium.googlesource.com/chromium/src/+/8f55866589a385c959b0e9f0a3bd1f70e4139a66

Patch Set 1 #

Patch Set 2 : initial value of selector_id_is_rightmost_ should be true. #

Patch Set 3 : Update tests. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+118 lines, -95 lines) Patch
M third_party/WebKit/Source/core/dom/SelectorQuery.h View 2 chunks +6 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/core/dom/SelectorQuery.cpp View 1 9 chunks +92 lines, -76 lines 0 comments Download
M third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp View 1 2 4 chunks +20 lines, -19 lines 0 comments Download

Messages

Total messages: 21 (17 generated)
esprehn
3 years, 8 months ago (2017-04-15 02:10:50 UTC) #11
dglazkov
lgtm
3 years, 8 months ago (2017-04-15 02:14:22 UTC) #13
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2820013002/40001
3 years, 8 months ago (2017-04-15 05:34:56 UTC) #18
commit-bot: I haz the power
3 years, 8 months ago (2017-04-15 08:58:36 UTC) #21
Message was sent while issue was closed.
Committed patchset #3 (id:40001) as
https://chromium.googlesource.com/chromium/src/+/8f55866589a385c959b0e9f0a3bd...

Powered by Google App Engine
This is Rietveld 408576698