Bug 216190 - [MotionMark] RenderLayer::paintLayerContents spends ~5% of the time in MonotonicTime::now() in Multiply
Summary: [MotionMark] RenderLayer::paintLayerContents spends ~5% of the time in Monoto...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-09-04 14:09 PDT by Wenson Hsieh
Modified: 2020-09-05 18:37 PDT (History)
15 users (show)

See Also:


Attachments
Patch (4.94 KB, patch)
2020-09-04 15:24 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch (6.41 KB, patch)
2020-09-04 15:25 PDT, Wenson Hsieh
simon.fraser: review-
Details | Formatted Diff | Diff
v2 (8.72 KB, patch)
2020-09-04 17:51 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
v3 (for EWS) (12.50 KB, patch)
2020-09-04 22:02 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
v3 (with test fix) (12.54 KB, patch)
2020-09-05 16:26 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wenson Hsieh 2020-09-04 14:09:43 PDT
See: PaintFrequencyTracker::begin()
Comment 1 Wenson Hsieh 2020-09-04 15:24:12 PDT Comment hidden (obsolete)
Comment 2 Wenson Hsieh 2020-09-04 15:24:48 PDT
Comment on attachment 408031 [details]
Patch

(Wrong patch :|)
Comment 3 Wenson Hsieh 2020-09-04 15:25:27 PDT
Created attachment 408032 [details]
Patch
Comment 4 Said Abou-Hallawa 2020-09-04 15:35:35 PDT
Comment on attachment 408032 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=408032&action=review

> Source/WebCore/rendering/RenderLayer.cpp:4632
> +    SinglePaintFrequencyTracking singlePaintFrequencyTracking(m_paintFrequencyTracker, FrameView::currentPaintTimeStamp() ?: MonotonicTime::now(), shouldPaintContent);

FrameView::currentPaintTimeStamp() ?: MonotonicTime::now()

Does this change compile?
Comment 5 Simon Fraser (smfr) 2020-09-04 15:44:50 PDT
Comment on attachment 408032 [details]
Patch

This all relies on sCurrentPaintTimeStamp which is updated from FrameView::willPaintContents(), but there can be paints that don't hit FrameView::willPaintContents() in they only touch non-main compositing layers.
Comment 6 Simon Fraser (smfr) 2020-09-04 15:45:35 PDT
^ if they only

It might also be fine to use the timestamp of the last Page::updateRendering() that maybe we stash somewhere?
Comment 7 Wenson Hsieh 2020-09-04 16:14:10 PDT
(In reply to Simon Fraser (smfr) from comment #6)
> ^ if they only
> 
> It might also be fine to use the timestamp of the last
> Page::updateRendering() that maybe we stash somewhere?

Sounds good! I’ll update this to stash a timestamp on `Page` in `Page::finalizeRenderingUpdate`, and then consult this timestamp in `RenderLayer::paintLayerContents`.
Comment 8 Wenson Hsieh 2020-09-04 17:51:40 PDT
Created attachment 408055 [details]
v2
Comment 9 Wenson Hsieh 2020-09-04 22:02:47 PDT
Created attachment 408065 [details]
v3 (for EWS)
Comment 10 Wenson Hsieh 2020-09-05 14:30:08 PDT
Thanks for taking a look! Since EWS doesn’t run debug WK2 tests, I figured I’d run them locally before landing. In doing so, I discovered that this actually causes the test "http/tests/security/navigate-when-restoring-cached-page.html" to assert underneath `PaintFrequencyTracker::end()`:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.apple.JavaScriptCore      	0x0000000137fa24fe WTFCrash + 14 (Assertions.cpp:295)
1   com.apple.WebCore             	0x000000011ad9911b WTFCrashWithInfo(int, char const*, char const*, int) + 27 (Assertions.h:671)
2   com.apple.WebCore             	0x000000011f10a58b WebCore::PaintFrequencyTracker::end() + 107 (PaintFrequencyTracker.h:70)
3   com.apple.WebCore             	0x000000011f10a51a WebCore::SinglePaintFrequencyTracking::~SinglePaintFrequencyTracking() + 42 (PaintFrequencyTracker.h:99)
4   com.apple.WebCore             	0x000000011f0c53e5 WebCore::SinglePaintFrequencyTracking::~SinglePaintFrequencyTracking() + 21 (PaintFrequencyTracker.h:97)
5   com.apple.WebCore             	0x000000011f0c060a WebCore::RenderLayer::paintLayerContents(WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 4442 (RenderLayer.cpp:4779)
6   com.apple.WebCore             	0x000000011f0bf42d WebCore::RenderLayer::paintLayerContentsAndReflection(WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 445 (RenderLayer.cpp:4413)
7   com.apple.WebCore             	0x000000011f0be2fa WebCore::RenderLayer::paintLayerWithEffects(WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 1370 (RenderLayer.cpp:4395)
8   com.apple.WebCore             	0x000000011f0bd460 WebCore::RenderLayer::paintLayer(WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 368 (RenderLayer.cpp:4330)
9   com.apple.WebCore             	0x000000011f0c3ec8 WebCore::RenderLayer::paintList(WebCore::RenderLayer::LayerList, WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 200 (RenderLayer.cpp:4831)
10  com.apple.WebCore             	0x000000011f0c015b WebCore::RenderLayer::paintLayerContents(WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 3243 (RenderLayer.cpp:4729)
11  com.apple.WebCore             	0x000000011f0bf42d WebCore::RenderLayer::paintLayerContentsAndReflection(WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 445 (RenderLayer.cpp:4413)
12  com.apple.WebCore             	0x000000011f0be2fa WebCore::RenderLayer::paintLayerWithEffects(WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 1370 (RenderLayer.cpp:4395)
13  com.apple.WebCore             	0x000000011f0bd460 WebCore::RenderLayer::paintLayer(WebCore::GraphicsContext&, WebCore::RenderLayer::LayerPaintingInfo const&, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>) + 368 (RenderLayer.cpp:4330)
14  com.apple.WebCore             	0x000000011f0bd162 WebCore::RenderLayer::paint(WebCore::GraphicsContext&, WebCore::LayoutRect const&, WebCore::LayoutSize const&, WTF::OptionSet<WebCore::PaintBehavior>, WebCore::RenderObject*, WTF::OptionSet<WebCore::RenderLayer::PaintLayerFlag>, WebCore::RenderLayer::SecurityOriginPaintPolicy, WebCore::EventRegionContext*) + 386 (RenderLayer.cpp:4188)
15  com.apple.WebCore             	0x000000011e769a2a WebCore::FrameView::paintContents(WebCore::GraphicsContext&, WebCore::IntRect const&, WebCore::Widget::SecurityOriginPaintPolicy, WebCore::EventRegionContext*) + 1930 (FrameView.cpp:4320)
16  com.apple.WebCore             	0x000000011e9cc8d4 WebCore::ScrollView::paint(WebCore::GraphicsContext&, WebCore::IntRect const&, WebCore::Widget::SecurityOriginPaintPolicy, WebCore::EventRegionContext*) + 740 (ScrollView.cpp:1277)
17  com.apple.WebCore             	0x000000011e769287 WebCore::FrameView::traverseForPaintInvalidation(WebCore::GraphicsContext::PaintInvalidationReasons) + 263 (FrameView.cpp:4175)
18  com.apple.WebCore             	0x000000011e76917a WebCore::FrameView::invalidateControlTints() + 26 (FrameView.h:659)
19  com.apple.WebCore             	0x000000011e7482ea WebCore::FrameView::updateControlTints() + 218 (FrameView.cpp:4159)
20  com.apple.WebCore             	0x000000011e747bc3 WebCore::FocusController::setActiveInternal(bool) + 99 (FocusController.cpp:912)
21  com.apple.WebCore             	0x000000011e747aec WebCore::FocusController::setActivityState(WTF::OptionSet<WebCore::ActivityState::Flag>) + 236 (FocusController.cpp:896)
22  com.apple.WebCore             	0x000000011e7c511b WebCore::Page::setActivityState(WTF::OptionSet<WebCore::ActivityState::Flag>) + 219 (Page.cpp:2106)
23  com.apple.WebKit              	0x000000010d08a060 WebKit::WebPage::setActivityState(WTF::OptionSet<WebCore::ActivityState::Flag>, unsigned long long, WTF::Vector<WebKit::CallbackID, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&) + 672 (WebPage.cpp:3286)
24  com.apple.WebKit              	0x000000010d089a07 WebKit::WebPage::reinitializeWebPage(WebKit::WebPageCreationParameters&&) + 679 (WebPage.cpp:844)
25  com.apple.WebKit              	0x000000010cb93ac6 WebKit::WebProcess::createWebPage(WTF::ObjectIdentifier<WebCore::PageIdentifierType>, WebKit::WebPageCreationParameters&&) + 342 (WebProcess.cpp:723)

It looks like Page::updateRendering() hadn’t been called yet when we try to paint while updating control tints, so the timestamp we pass to SinglePaintFrequencyTracking ends up being 0.
Comment 11 Wenson Hsieh 2020-09-05 14:39:34 PDT
> It looks like Page::updateRendering() hadn’t been called yet when we try to
> paint while updating control tints, so the timestamp we pass to
> SinglePaintFrequencyTracking ends up being 0.

I think I can fix this by making not tracking paint frequency for paints that are just for paint invalidation (i.e., `GraphicsContext` contains `m_paintInvalidationReasons`)...
Comment 12 Wenson Hsieh 2020-09-05 16:26:25 PDT
Created attachment 408103 [details]
v3 (with test fix)
Comment 13 EWS 2020-09-05 18:36:16 PDT
Committed r266677: <https://trac.webkit.org/changeset/266677>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408103 [details].
Comment 14 Radar WebKit Bug Importer 2020-09-05 18:37:15 PDT
<rdar://problem/68409128>