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

Issue 15871005: Avoid N^2 walk placing renderers when building the render tree (Closed)

Created:
7 years, 6 months ago by leviw_travelin_and_unemployed
Modified:
7 years, 5 months ago
Reviewers:
ojan, jamesr, esprehn, eae, eseidel
CC:
blink-reviews, webcomponents-bugzilla_chromium.org, eae+blinkwatch, dglazkov+blink, apavlov+blink_chromium.org, adamk+blink_chromium.org, darktears
Base URL:
https://chromium.googlesource.com/chromium/blink.git@master
Visibility:
Public.

Description

Avoid N^2 walk placing renderers when building the render tree Blink resolves style by walking each element from first children to last, but when we go to insert their renderer, we look for the next renderer to insert before. On the initial style resolve, this means we'll walk the entire DOM tree trying to find the right renderer to insert before leading to an N^2 loop over the DOM on load. This could be fixed by changing the semantics by which we insert renderers (insert after instead of insert before). Instead, here I reverse the order we resolve style. This should ensure that in the common case, we'll find the renderer to insert before immediately. While looking at this, I also found we have an N^2 loop for resolving Nth last child selectors, and reversing the style resolve loop would have caused the same issue for Nth child selectors. To fix prevent this regression, I'm piping the child index down to the style resolver in the common case. This ensures both Nth and Nth last should usually be O(1). Using the microbenchmark created for lazy layout, http://elliottsprehn.com/personal/lazyblock/, this yields a speedup of nearly 50% (4.75s -> 2.51s). BUG=245478 Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=151996

Patch Set 1 #

Patch Set 2 : Merging ToT #

Total comments: 2

Patch Set 3 : Adding comments and updated test expectations #

Patch Set 4 : Again, updating to ToT. #

Total comments: 4

Patch Set 5 : Addressing comments. #

Total comments: 3

Patch Set 6 : Reversing the snapshotting logic to fix a bug, and updating test expectations. #

Total comments: 4

Patch Set 7 : Fix failing tests #

Patch Set 8 : Merging ToT #

Total comments: 1

Patch Set 9 : Adding a mitigation for the perf regression to Element::recalcStyle. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+171 lines, -76 lines) Patch
M LayoutTests/fast/dom/HTMLLinkElement/resolve-url-on-insertion-expected.txt View 1 2 1 chunk +0 lines, -2 lines 0 comments Download
M LayoutTests/http/tests/cache/subresource-expiration-1-expected.txt View 1 2 3 4 5 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/http/tests/cache/subresource-expiration-2-expected.txt View 1 2 3 4 5 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-linux/fast/html/details-replace-text-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/editing/selection/caret-ltr-2-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/editing/selection/caret-ltr-2-left-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/editing/selection/caret-ltr-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/editing/selection/caret-ltr-right-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/editing/selection/caret-rtl-2-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/editing/selection/caret-rtl-2-left-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/editing/selection/caret-rtl-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/editing/selection/caret-rtl-right-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/fast/html/details-add-child-2-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M LayoutTests/platform/chromium-win/fast/html/details-open2-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -1 line 0 comments Download
M Source/core/css/SelectorChecker.h View 1 2 3 4 5 6 7 8 3 chunks +3 lines, -1 line 0 comments Download
M Source/core/css/SelectorChecker.cpp View 1 2 3 4 5 6 7 8 2 chunks +4 lines, -2 lines 0 comments Download
M Source/core/css/SiblingTraversalStrategies.h View 1 2 3 4 2 chunks +14 lines, -9 lines 0 comments Download
M Source/core/css/resolver/StyleResolver.h View 1 2 3 4 5 6 7 8 2 chunks +8 lines, -2 lines 0 comments Download
M Source/core/css/resolver/StyleResolver.cpp View 1 2 3 4 5 6 7 8 7 chunks +10 lines, -10 lines 0 comments Download
M Source/core/css/resolver/StyleResolverState.h View 1 2 3 4 5 6 7 8 4 chunks +4 lines, -1 line 0 comments Download
M Source/core/css/resolver/StyleResolverState.cpp View 1 2 3 4 5 6 7 8 2 chunks +3 lines, -1 line 0 comments Download
M Source/core/dom/ContainerNode.h View 1 2 3 4 5 6 7 8 8 chunks +30 lines, -5 lines 0 comments Download
M Source/core/dom/ContainerNode.cpp View 1 2 3 4 5 6 7 8 4 chunks +40 lines, -4 lines 0 comments Download
M Source/core/dom/ContainerNodeAlgorithms.h View 1 2 3 4 5 6 7 8 1 chunk +3 lines, -2 lines 0 comments Download
M Source/core/dom/ContainerNodeAlgorithms.cpp View 1 2 3 4 5 2 chunks +2 lines, -2 lines 0 comments Download
M Source/core/dom/Document.cpp View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M Source/core/dom/Element.h View 1 2 3 4 5 6 7 8 2 chunks +3 lines, -3 lines 0 comments Download
M Source/core/dom/Element.cpp View 1 2 3 4 5 6 7 8 4 chunks +25 lines, -13 lines 0 comments Download
M Source/core/dom/ScriptElement.h View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -0 lines 0 comments Download
M Source/core/dom/ScriptElement.cpp View 1 2 3 4 5 6 7 8 1 chunk +7 lines, -1 line 0 comments Download
M Source/core/dom/Text.cpp View 1 2 3 4 5 6 7 8 1 chunk +3 lines, -1 line 0 comments Download
M Source/core/dom/shadow/ShadowRoot.cpp View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M Source/core/html/HTMLInputElement.h View 1 2 3 4 5 6 7 8 1 chunk +1 line, -0 lines 0 comments Download
M Source/core/html/HTMLInputElement.cpp View 1 2 3 4 5 6 7 8 1 chunk +7 lines, -2 lines 0 comments Download

Messages

Total messages: 15 (0 generated)
leviw_travelin_and_unemployed
7 years, 6 months ago (2013-05-31 00:15:00 UTC) #1
leviw_travelin_and_unemployed
The test failure is confusing, but reproduces locally. There are two less empty lines on ...
7 years, 6 months ago (2013-05-31 02:46:35 UTC) #2
ojan
+a few other people who know about style recalc. I wonder if we should create ...
7 years, 6 months ago (2013-05-31 18:05:07 UTC) #3
leviw_travelin_and_unemployed
Added some more comments and updated the test expectations. In the lazy block microbenchmark, this ...
7 years, 6 months ago (2013-06-03 21:34:22 UTC) #4
ojan
This looks good modulo the couple comments below. Also, can we attach this benchmark to ...
7 years, 6 months ago (2013-06-03 23:03:29 UTC) #5
eseidel
Elliot is your best reviewer here. but lgtm. childIndex being 0 is confusing. https://codereview.chromium.org/15871005/diff/18015/Source/core/css/resolver/StyleResolver.cpp File ...
7 years, 6 months ago (2013-06-04 06:29:35 UTC) #6
leviw_travelin_and_unemployed
On 2013/06/04 06:29:35, eseidel wrote: > Elliot is your best reviewer here. but lgtm. childIndex ...
7 years, 6 months ago (2013-06-04 21:17:39 UTC) #7
ojan
lgtm
7 years, 6 months ago (2013-06-04 23:52:37 UTC) #8
esprehn
You have an unneeded isTextNode() check. We should watch the perf bots since this means ...
7 years, 6 months ago (2013-06-05 00:12:26 UTC) #9
leviw_travelin_and_unemployed
PTAL. I had to make 2 more changes to get all the tests passing. This ...
7 years, 6 months ago (2013-06-06 23:41:34 UTC) #10
eseidel
lgtm https://codereview.chromium.org/15871005/diff/42001/LayoutTests/http/tests/cache/subresource-expiration-1-expected.txt File LayoutTests/http/tests/cache/subresource-expiration-1-expected.txt (left): https://codereview.chromium.org/15871005/diff/42001/LayoutTests/http/tests/cache/subresource-expiration-1-expected.txt#oldcode12 LayoutTests/http/tests/cache/subresource-expiration-1-expected.txt:12: These are empty text nodes no longer being ...
7 years, 6 months ago (2013-06-06 23:47:57 UTC) #11
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/leviw@chromium.org/15871005/42001
7 years, 6 months ago (2013-06-06 23:48:11 UTC) #12
commit-bot: I haz the power
Change committed as 151996
7 years, 6 months ago (2013-06-07 04:48:28 UTC) #13
eseidel
https://code.google.com/p/chromium/issues/detail?id=248058 claims this caused a big perf regression.
7 years, 6 months ago (2013-06-10 20:38:36 UTC) #14
ojan
7 years, 5 months ago (2013-07-10 23:24:01 UTC) #15
Message was sent while issue was closed.
lgtm

You and Elliot can fight over who gets to land their patch first...

Powered by Google App Engine
This is Rietveld 408576698