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

Issue 1023393002: Cache element indices for :nth-child and :nth-last-child selectors. (Closed)

Created:
5 years, 9 months ago by rune
Modified:
5 years, 8 months ago
Reviewers:
esprehn, sof
CC:
darktears, apavlov+blink_chromium.org, blink-reviews, blink-reviews-css, blink-reviews-dom_chromium.org, blink-reviews-html_chromium.org, blink-reviews-style_chromium.org, dglazkov+blink, eae+blinkwatch, ed+blinkwatch_opera.com, rwlbuis
Base URL:
https://chromium.googlesource.com/chromium/blink.git@master
Target Ref:
refs/heads/master
Project:
blink
Visibility:
Public.

Description

Cache element indices for :nth-child and :nth-last-child selectors. In order to avoid n^2 for :nth-selectors, we introduce a cache where we store the index of every kth child of a parent node P the first time the nth-count is queried for one of its children. The number k is given by the "spread" constant. After the cache has been populated for the children of P, the nth-index for an element will be found by walking the siblings from the element queried for and leftwards until a cached element/index pair is found. So populating the cache for P is O(n). Subsequent lookups are best case O(1), worst case O(k). The cache is created on the stack when we do operations where we know we can benefit from having it. Currently, those are querySelector, querySelectorAll, and updateStyle. We are throwing away the cache after each operation to avoid holding on to potentially large caches in memory. R=esprehn@chromium.org BUG=461878 Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=193268

Patch Set 1 #

Patch Set 2 : Keep cache on Document, inlining, and tweaking spread. #

Patch Set 3 : Oilpan tracing and removed unused nth-of-type. #

Patch Set 4 : Wrote tests #

Patch Set 5 : Split out include file fix #

Patch Set 6 : Rebase and oilpan fixes #

Patch Set 7 : Clear cache after each operation #

Total comments: 14

Patch Set 8 : Fixed review issues from sof #

Total comments: 2

Patch Set 9 : Moved nth-index-cache scope to updateStyle #

Total comments: 2

Patch Set 10 : Moved NthIndexCacheScope #

Total comments: 6

Patch Set 11 : More review issues #

Total comments: 3

Patch Set 12 : Back to stack-based cache #

Total comments: 9

Patch Set 13 : Review issues #

Patch Set 14 : Rebased #

Patch Set 15 : Store NthCacheIndex on Document #

Patch Set 16 : Rebased #

Patch Set 17 : Missing initializer and incorrect assert. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+297 lines, -0 lines) Patch
A LayoutTests/fast/dom/SelectorAPI/document-fragment-nth.html View 1 2 3 1 chunk +15 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/SelectorAPI/document-fragment-nth-expected.txt View 1 2 3 1 chunk +10 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/SelectorAPI/loose-subtree-nth.html View 1 2 3 1 chunk +15 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/SelectorAPI/loose-subtree-nth-expected.txt View 1 2 3 1 chunk +10 lines, -0 lines 0 comments Download
M Source/core/core.gypi View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 chunks +3 lines, -0 lines 0 comments Download
M Source/core/css/SiblingTraversalStrategies.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 3 chunks +8 lines, -0 lines 0 comments Download
M Source/core/dom/ContainerNode.cpp View 1 2 3 4 5 6 7 8 9 10 11 12 13 3 chunks +4 lines, -0 lines 0 comments Download
M Source/core/dom/Document.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 5 chunks +14 lines, -0 lines 0 comments Download
M Source/core/dom/Document.cpp View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 chunks +3 lines, -0 lines 0 comments Download
A Source/core/dom/NthIndexCache.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +91 lines, -0 lines 0 comments Download
A Source/core/dom/NthIndexCache.cpp View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +72 lines, -0 lines 0 comments Download
A Source/core/dom/NthIndexCacheTest.cpp View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +52 lines, -0 lines 0 comments Download

Messages

Total messages: 45 (13 generated)
rune
5 years, 9 months ago (2015-03-26 11:16:40 UTC) #2
rune
sof: could you take a look at the oilpanification of NthIndexCache and NthIndexData to see ...
5 years, 9 months ago (2015-03-26 11:21:17 UTC) #4
rune
In patch set 7, we now clear the cache after each querySelector/querySelectorAll/updateRenderTree.
5 years, 9 months ago (2015-03-27 14:10:02 UTC) #5
sof
Sorry, this CL escaped my attention yesterday -- some Oilpan feedback. https://codereview.chromium.org/1023393002/diff/120001/Source/core/dom/Document.cpp File Source/core/dom/Document.cpp (right): ...
5 years, 9 months ago (2015-03-28 08:34:00 UTC) #6
rune
https://codereview.chromium.org/1023393002/diff/120001/Source/core/dom/Document.cpp File Source/core/dom/Document.cpp (right): https://codereview.chromium.org/1023393002/diff/120001/Source/core/dom/Document.cpp#newcode666 Source/core/dom/Document.cpp:666: m_nthIndexCache = adoptPtr(new NthIndexCache(*this)); On 2015/03/28 08:33:59, sof wrote: ...
5 years, 8 months ago (2015-03-30 09:00:03 UTC) #7
sof
oilpan lgtm https://codereview.chromium.org/1023393002/diff/120001/Source/core/dom/Document.h File Source/core/dom/Document.h (right): https://codereview.chromium.org/1023393002/diff/120001/Source/core/dom/Document.h#newcode1067 Source/core/dom/Document.h:1067: public: On 2015/03/30 09:00:03, rune wrote: > ...
5 years, 8 months ago (2015-03-30 13:27:53 UTC) #8
rune
So, I've moved the NthIndexCacheScope to NthIndexCache.h and made it a friend of Document. https://codereview.chromium.org/1023393002/diff/140001/Source/core/dom/Document.h ...
5 years, 8 months ago (2015-03-30 20:14:40 UTC) #9
sof
Thanks for moving the scope object. Sorry about the late double-checking, but noticed a transition ...
5 years, 8 months ago (2015-03-30 20:55:17 UTC) #10
rune
https://codereview.chromium.org/1023393002/diff/180001/Source/core/dom/NthIndexCache.h File Source/core/dom/NthIndexCache.h (right): https://codereview.chromium.org/1023393002/diff/180001/Source/core/dom/NthIndexCache.h#newcode19 Source/core/dom/NthIndexCache.h:19: class NthIndexCache : NoBaseWillBeGarbageCollected<NthIndexCache> { On 2015/03/30 20:55:17, sof ...
5 years, 8 months ago (2015-03-30 22:01:45 UTC) #11
esprehn
Instead of all this adding and clearing I'd just use the stack to manage this: ...
5 years, 8 months ago (2015-03-30 22:55:31 UTC) #12
rune
On 2015/03/30 22:55:31, esprehn wrote: > Instead of all this adding and clearing I'd just ...
5 years, 8 months ago (2015-03-30 23:39:36 UTC) #13
esprehn
On 2015/03/30 at 23:39:36, rune wrote: > On 2015/03/30 22:55:31, esprehn wrote: > > .. ...
5 years, 8 months ago (2015-03-31 00:14:52 UTC) #14
sof
On 2015/03/30 23:39:36, rune wrote: > On 2015/03/30 22:55:31, esprehn wrote: > > Instead of ...
5 years, 8 months ago (2015-03-31 09:48:29 UTC) #15
rune
Now back to a stack-based cache ...
5 years, 8 months ago (2015-03-31 11:04:56 UTC) #16
sof
On 2015/03/31 11:04:56, rune wrote: > Now back to a stack-based cache ... ..and let's ...
5 years, 8 months ago (2015-03-31 16:59:04 UTC) #17
sof
https://codereview.chromium.org/1023393002/diff/220001/Source/core/dom/NthIndexCache.h File Source/core/dom/NthIndexCache.h (right): https://codereview.chromium.org/1023393002/diff/220001/Source/core/dom/NthIndexCache.h#newcode26 Source/core/dom/NthIndexCache.h:26: static NthIndexCache* getInstance() { return s_instance; } nit: instance() ...
5 years, 8 months ago (2015-03-31 16:59:21 UTC) #18
esprehn
lgtm w/ nits. Thanks for fixing this! https://codereview.chromium.org/1023393002/diff/220001/Source/core/dom/NthIndexCache.cpp File Source/core/dom/NthIndexCache.cpp (right): https://codereview.chromium.org/1023393002/diff/220001/Source/core/dom/NthIndexCache.cpp#newcode44 Source/core/dom/NthIndexCache.cpp:44: const unsigned ...
5 years, 8 months ago (2015-03-31 17:35:15 UTC) #19
rune
https://codereview.chromium.org/1023393002/diff/220001/Source/core/dom/NthIndexCache.cpp File Source/core/dom/NthIndexCache.cpp (right): https://codereview.chromium.org/1023393002/diff/220001/Source/core/dom/NthIndexCache.cpp#newcode44 Source/core/dom/NthIndexCache.cpp:44: const unsigned spread = 3; On 2015/03/31 17:35:15, esprehn ...
5 years, 8 months ago (2015-03-31 20:57:37 UTC) #20
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1023393002/260001
5 years, 8 months ago (2015-03-31 20:59:06 UTC) #23
rune
On 2015/03/31 16:59:04, sof wrote: > On 2015/03/31 11:04:56, rune wrote: > > Now back ...
5 years, 8 months ago (2015-03-31 22:24:34 UTC) #24
esprehn
On 2015/03/31 at 22:24:34, rune wrote: > On 2015/03/31 16:59:04, sof wrote: > > On ...
5 years, 8 months ago (2015-03-31 22:47:05 UTC) #26
esprehn
Also sorry for all the iteration on this :(
5 years, 8 months ago (2015-03-31 22:47:14 UTC) #27
rune
On 2015/03/31 22:47:05, esprehn wrote: > On 2015/03/31 at 22:24:34, rune wrote: > > On ...
5 years, 8 months ago (2015-04-04 14:28:35 UTC) #28
sof
On 2015/04/04 14:28:35, OOO (back 2015-04-07) wrote: > On 2015/03/31 22:47:05, esprehn wrote: > > ...
5 years, 8 months ago (2015-04-04 18:29:06 UTC) #29
rune
On 2015/04/04 18:29:06, sof wrote: > Something like, > GC_PLUGIN_IGNORE("461878") > NthIndexCache* m_nthIndexCache; Done.
5 years, 8 months ago (2015-04-07 07:22:28 UTC) #30
sof
lgtm
5 years, 8 months ago (2015-04-07 07:45:51 UTC) #31
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1023393002/280001
5 years, 8 months ago (2015-04-07 08:02:38 UTC) #34
commit-bot: I haz the power
Try jobs failed on following builders: mac_blink_compile_dbg on tryserver.blink (JOB_FAILED, http://build.chromium.org/p/tryserver.blink/builders/mac_blink_compile_dbg/builds/41001) mac_blink_rel on tryserver.blink (JOB_FAILED, ...
5 years, 8 months ago (2015-04-07 08:07:31 UTC) #36
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1023393002/300001
5 years, 8 months ago (2015-04-07 08:25:58 UTC) #39
commit-bot: I haz the power
Try jobs failed on following builders: linux_blink_rel on tryserver.blink (JOB_FAILED, http://build.chromium.org/p/tryserver.blink/builders/linux_blink_rel/builds/56168)
5 years, 8 months ago (2015-04-07 09:16:16 UTC) #41
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1023393002/320001
5 years, 8 months ago (2015-04-07 12:33:28 UTC) #44
commit-bot: I haz the power
5 years, 8 months ago (2015-04-07 14:00:46 UTC) #45
Message was sent while issue was closed.
Committed patchset #17 (id:320001) as
https://src.chromium.org/viewvc/blink?view=rev&revision=193268

Powered by Google App Engine
This is Rietveld 408576698