New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 668300 link

Starred by 2 users

Issue metadata

Status: Archived
Owner:
Closed: Aug 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

RELEASE_ASSERTs in much hotter code than needed?

Project Member Reported by danakj@chromium.org, Nov 23 2016

Issue description

RELEASE_ASSERT()s being changed to CHECK()s caused performance regressions in layout perf tests on Windows 64bit. Between 2%-20% regressions were seen.

The actual asm implementation of RELEASE_ASSERT and CHECK is identical, but the compiler output over all of blink was changed somehow by the presence of the unused stream operator on CHECK.

I believe this hints at RELEASE_ASSERT being present in very hot code, which is likely unnecessary and could be hoisted out while providing the same verification. This should translate to real perf wins since such a minute change (actually 0 asm change) was very visible on the bots.

Here's is a run of the bots, where the patch being tested was with CHECK() replacement of RELEASE_ASSERT(): http://storage.googleapis.com/chromium-telemetry/html-results/results-2016-06-01_15-50-44

Here's the CL for that perf test run: https://codereview.chromium.org/1992873004/

Here's an email thread discussing this from the POV of "what's wrong with CHECK?" https://groups.google.com/a/chromium.org/d/topic/blink-dev/TL0NkNXIT1w/discussion

pdr suggested that it would probably be really interesting to make RELEASE_ASSERT artificially expensive, run these perf tests in pprof, and see which ones are being hammered the most.
 

Comment 1 Deleted

Comment 2 Deleted

Comment 3 by tkent@chromium.org, Nov 24 2016

Cc: tkent@chromium.org
One example is Vector::at(size_t).  This function is very small, and very hot.
Though I'm not sure if we can remove RELEASE_ASSERT in at(), we can avoid to call at() like the following change:

for (size_t i = 0; i < vector.size(); ++i)
  foo(vector[i]);  // operator[] is an alias of at().

  ↓

for (const auto& t : vector)
  foo(t); // 
FTR I did some archaeology as the history of this is quite convoluted

#384213 : Replace all occurrences of RELEASE_ASSERT in wtf with CHECK. (crrev.com/1840163002)
#384889 : reverted (crrev.com/1854033002) because of android perf regresson  crbug.com/599867 
#394035 : nico making CHECK false using __builtin_trap  (crrev.com/1982123002)
#395624 : Replace all occurrences of RELEASE_ASSERT in wtf with CHECK. (crrev.com/1992873004)
#396441 : reverted (crrev.com/2016223002) because of windows perf regression ( crbug.com/614852 )      
#398084 : primiano reverts nico's beacause of crash stuff (crrev.com/2046593002)
#404249 : primiano relands nico's, crash stuff fixed (crrev.com/2125923002)

Looks like on the 2nd attempt it was reverted because of a regression on windows only ( crbug.com/614852 ).
note that the UNLIKELY is irrelevant here as both in base and wtf it was a no-op on win.

The two macros (CHECK and RELEASE_ASSERT) are identical % the EAT_STREAM_PARAMETER part, which might be what tkent observed in
https://groups.google.com/a/chromium.org/d/msg/blink-dev/TL0NkNXIT1w/mbMCKqymBQAJ

Comment 5 by e...@chromium.org, Dec 2 2016

Status: Available (was: Untriaged)
Project Member

Comment 6 by bugdroid1@chromium.org, Dec 7 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/a9f3df455d2ea2b360dda396e86df6fdff49dbe8

commit a9f3df455d2ea2b360dda396e86df6fdff49dbe8
Author: tkent <tkent@chromium.org>
Date: Wed Dec 07 05:53:04 2016

Avoid WTF::Vector::at() and operator[] in core/dom.

at() and operator[] are slow due to RELEASE_ASSERT. We can avoid the slowness by
range-based |for|.

This CL has no behavior changes except runtime performance.

BUG= 668300 

Review-Url: https://codereview.chromium.org/2553343002
Cr-Commit-Position: refs/heads/master@{#436875}

[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/CSSSelectorWatch.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/ClientRectList.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/CompositorProxy.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/DOMStringList.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/DOMTokenList.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/FrameRequestCallbackCollection.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/MutationObserver.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/Node.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/ScriptedAnimationController.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/SpaceSplitString.h
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/StyleEngine.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/TreeScopeStyleSheetCollection.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/custom/V0CustomElementAsyncImportMicrotaskQueue.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/custom/V0CustomElementMicrotaskQueueBase.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/shadow/ElementShadowV0.cpp
[modify] https://crrev.com/a9f3df455d2ea2b360dda396e86df6fdff49dbe8/third_party/WebKit/Source/core/dom/shadow/InsertionPoint.cpp

Project Member

Comment 8 by bugdroid1@chromium.org, Dec 8 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/f5775c2f04c255de2fe9f68ff8444d3f987901a4

commit f5775c2f04c255de2fe9f68ff8444d3f987901a4
Author: tkent <tkent@chromium.org>
Date: Thu Dec 08 04:12:13 2016

Avoid WTF::Vector::at() and operator[] in core/html.

at() and operator[] are slow due to RELEASE_ASSERT. We can avoid the slowness by
range-based |for|.

This CL has no behavior changes except runtime performance.

BUG= 668300 

Review-Url: https://codereview.chromium.org/2556043002
Cr-Commit-Position: refs/heads/master@{#437175}

[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/HTMLCollection.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/HTMLElement.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/HTMLFormControlsCollection.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/HTMLFormElement.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/MediaFragmentURIParser.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/PublicURLManager.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/forms/FileInputType.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/forms/FormController.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/imports/HTMLImport.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/imports/HTMLImportLoader.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/imports/HTMLImportTreeRoot.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/imports/HTMLImportsController.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/parser/AtomicHTMLToken.h
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/parser/BackgroundHTMLInputStream.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/parser/HTMLConstructionSite.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/parser/HTMLFormattingElementList.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/parser/HTMLTreeBuilder.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/shadow/DateTimeEditElement.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/track/AutomaticTrackSelection.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/track/CueTimeline.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/track/TextTrackContainer.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/track/TextTrackCueList.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/track/TextTrackList.cpp
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/track/TrackListBase.h
[modify] https://crrev.com/f5775c2f04c255de2fe9f68ff8444d3f987901a4/third_party/WebKit/Source/core/html/track/vtt/VTTRegionList.cpp

Note that replacing all of the indexed access with range loops is great, but I don't think that allows us to regress the performance of operator[] with CHECK. We need to make CHECK fast, we can't hack around it inside blink.

Note also that post-fork Apple added these same asserts to the iterators for added security. We might consider doing the same thing, which means switching to range based for loops here is not a fix for CHECK being slow.

Comment 12 by e...@chromium.org, Aug 1 2017

Status: Archived (was: Available)

Sign in to add a comment