Skip to content

Commit cbeb30c

Browse files
Migrate some layout timer-related code from std::chrono to Seconds and MonotonicTime
https://bugs.webkit.org/show_bug.cgi?id=164992 Reviewed by Darin Adler. Source/WebCore: std::chrono::milliseconds -> Seconds. Rename Document::elapsedTime() to timeSinceDocumentCreation() which is more explicit. Replace INSTRUMENT_LAYOUT_SCHEDULING with LOG(Layout...). * dom/Document.cpp: (WebCore::Document::Document): (WebCore::Document::implicitClose): (WebCore::Document::isLayoutTimerActive): (WebCore::Document::minimumLayoutDelay): (WebCore::Document::timeSinceDocumentCreation): (WebCore::Document::elapsedTime): Deleted. * dom/Document.h: * page/ChromeClient.h: * page/FrameView.cpp: (WebCore::FrameView::layout): (WebCore::FrameView::scrollPositionChanged): (WebCore::FrameView::layoutTimerFired): (WebCore::FrameView::scheduleRelayout): (WebCore::FrameView::scheduleRelayoutOfSubtree): (WebCore::FrameView::unscheduleRelayout): * page/Settings.cpp: (WebCore::Settings::setLayoutInterval): * page/Settings.h: (WebCore::Settings::layoutInterval): * style/StyleScope.cpp: (WebCore::Style::Scope::removePendingSheet): * workers/WorkerRunLoop.cpp: (WebCore::WorkerRunLoop::runInMode): Source/WebKit2: No more ugly conversion from seconds to milliseconds. * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::updatePreferences): * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::eventThrottlingDelay): Source/WTF: Add Seconds::zero() as a nicer way to express Seconds(0). * wtf/Seconds.h: (WTF::Seconds::zero): Tools: Use Seconds::zero(). * TestWebKitAPI/Tests/WTF/Condition.cpp: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@208982 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 721cb2a commit cbeb30c

File tree

24 files changed

+131
-59
lines changed

24 files changed

+131
-59
lines changed

Source/JavaScriptCore/runtime/AtomicsObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ EncodedJSValue JSC_HOST_CALL atomicsFuncWait(ExecState* exec)
315315
// exec->argument(3) returns undefined if it's not provided and ToNumber(undefined) returns NaN,
316316
// so NaN is the only special case.
317317
if (timeout == timeout)
318-
timeout = std::max(Seconds(0), timeout);
318+
timeout = std::max(0_s, timeout);
319319
else
320320
timeout = Seconds::infinity();
321321

Source/WTF/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2016-11-26 Simon Fraser <[email protected]>
2+
3+
Migrate some layout timer-related code from std::chrono to Seconds and MonotonicTime
4+
https://bugs.webkit.org/show_bug.cgi?id=164992
5+
6+
Reviewed by Darin Adler.
7+
8+
Add Seconds::zero() as a nicer way to express Seconds(0).
9+
10+
* wtf/Seconds.h:
11+
(WTF::Seconds::zero):
12+
113
2016-11-26 Simon Fraser <[email protected]>
214

315
Add literals for various time units

Source/WTF/wtf/AutomaticThread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void AutomaticThread::start(const LockHolder&)
181181
RELEASE_ASSERT(result == PollResult::Wait);
182182
// Shut the thread down after one second.
183183
bool awokenByNotify =
184-
m_condition->m_condition.waitFor(*m_lock, Seconds(1));
184+
m_condition->m_condition.waitFor(*m_lock, 1_s);
185185
if (!awokenByNotify) {
186186
if (verbose)
187187
dataLog(RawPointer(this), ": Going to sleep!\n");

Source/WTF/wtf/Seconds.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ class Seconds {
201201
double m_value { 0 };
202202
};
203203

204+
inline namespace seconds_literals {
205+
204206
constexpr Seconds operator"" _min(long double minutes)
205207
{
206208
return Seconds::fromMinutes(minutes);
@@ -251,10 +253,13 @@ constexpr Seconds operator"" _ns(unsigned long long nanoseconds)
251253
return Seconds::fromNanoseconds(nanoseconds);
252254
}
253255

256+
} // inline seconds_literals
257+
254258
WTF_EXPORT_PRIVATE void sleep(Seconds);
255259

256-
} // namespae WTF
260+
} // namespace WTF
257261

262+
using namespace WTF::seconds_literals;
258263
using WTF::Seconds;
259264

260265
#endif // WTF_Seconds_h

Source/WebCore/ChangeLog

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
2016-11-26 Simon Fraser <[email protected]>
2+
3+
Migrate some layout timer-related code from std::chrono to Seconds and MonotonicTime
4+
https://bugs.webkit.org/show_bug.cgi?id=164992
5+
6+
Reviewed by Darin Adler.
7+
8+
std::chrono::milliseconds -> Seconds.
9+
10+
Rename Document::elapsedTime() to timeSinceDocumentCreation() which is more explicit.
11+
12+
Replace INSTRUMENT_LAYOUT_SCHEDULING with LOG(Layout...).
13+
14+
* dom/Document.cpp:
15+
(WebCore::Document::Document):
16+
(WebCore::Document::implicitClose):
17+
(WebCore::Document::isLayoutTimerActive):
18+
(WebCore::Document::minimumLayoutDelay):
19+
(WebCore::Document::timeSinceDocumentCreation):
20+
(WebCore::Document::elapsedTime): Deleted.
21+
* dom/Document.h:
22+
* page/ChromeClient.h:
23+
* page/FrameView.cpp:
24+
(WebCore::FrameView::layout):
25+
(WebCore::FrameView::scrollPositionChanged):
26+
(WebCore::FrameView::layoutTimerFired):
27+
(WebCore::FrameView::scheduleRelayout):
28+
(WebCore::FrameView::scheduleRelayoutOfSubtree):
29+
(WebCore::FrameView::unscheduleRelayout):
30+
* page/Settings.cpp:
31+
(WebCore::Settings::setLayoutInterval):
32+
* page/Settings.h:
33+
(WebCore::Settings::layoutInterval):
34+
* style/StyleScope.cpp:
35+
(WebCore::Style::Scope::removePendingSheet):
36+
* workers/WorkerRunLoop.cpp:
37+
(WebCore::WorkerRunLoop::runInMode):
38+
139
2016-11-26 Simon Fraser <[email protected]>
240

341
Composited negative z-index elements are hidden behind the body sometimes

Source/WebCore/dom/Document.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ Document::Document(Frame* frame, const URL& url, unsigned documentClasses, unsig
468468
, m_cssTarget(nullptr)
469469
, m_processingLoadEvent(false)
470470
, m_loadEventFinished(false)
471-
, m_startTime(std::chrono::steady_clock::now())
471+
, m_documentCreationTime(MonotonicTime::now())
472472
, m_overMinimumLayoutThreshold(false)
473473
, m_scriptRunner(std::make_unique<ScriptRunner>(*this))
474474
, m_moduleLoader(std::make_unique<ScriptModuleLoader>(*this))
@@ -2696,7 +2696,7 @@ void Document::implicitClose()
26962696
// fires. This will improve onload scores, and other browsers do it.
26972697
// If they wanna cheat, we can too. -dwh
26982698

2699-
if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < settings()->layoutInterval()) {
2699+
if (frame()->navigationScheduler().locationChangePending() && timeSinceDocumentCreation() < settings()->layoutInterval()) {
27002700
// Just bail out. Before or during the onload we were shifted to another page.
27012701
// The old i-Bench suite does this. When this happens don't bother painting or laying out.
27022702
m_processingLoadEvent = false;
@@ -2770,26 +2770,24 @@ bool Document::shouldScheduleLayout()
27702770

27712771
bool Document::isLayoutTimerActive()
27722772
{
2773-
return view() && view()->layoutPending() && !minimumLayoutDelay().count();
2773+
return view() && view()->layoutPending() && !minimumLayoutDelay();
27742774
}
27752775

2776-
std::chrono::milliseconds Document::minimumLayoutDelay()
2776+
Seconds Document::minimumLayoutDelay()
27772777
{
27782778
if (m_overMinimumLayoutThreshold)
2779-
return 0ms;
2779+
return 0_s;
27802780

2781-
auto elapsed = elapsedTime();
2781+
auto elapsed = timeSinceDocumentCreation();
27822782
m_overMinimumLayoutThreshold = elapsed > settings()->layoutInterval();
27832783

27842784
// We'll want to schedule the timer to fire at the minimum layout threshold.
2785-
return std::max(0ms, settings()->layoutInterval() - elapsed);
2785+
return std::max(0_s, settings()->layoutInterval() - elapsed);
27862786
}
27872787

2788-
std::chrono::milliseconds Document::elapsedTime() const
2788+
Seconds Document::timeSinceDocumentCreation() const
27892789
{
2790-
auto elapsedTime = std::chrono::steady_clock::now() - m_startTime;
2791-
2792-
return std::chrono::duration_cast<std::chrono::milliseconds>(elapsedTime);
2790+
return MonotonicTime::now() - m_documentCreationTime;
27932791
}
27942792

27952793
void Document::write(const SegmentedString& text, Document* ownerDocument)

Source/WebCore/dom/Document.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,11 @@ class Document
671671
void setReadyState(ReadyState);
672672
void setParsing(bool);
673673
bool parsing() const { return m_bParsing; }
674-
std::chrono::milliseconds minimumLayoutDelay();
674+
Seconds minimumLayoutDelay();
675675

676676
bool shouldScheduleLayout();
677677
bool isLayoutTimerActive();
678-
std::chrono::milliseconds elapsedTime() const;
678+
Seconds timeSinceDocumentCreation() const;
679679

680680
void setTextColor(const Color& color) { m_textColor = color; }
681681
const Color& textColor() const { return m_textColor; }
@@ -1527,7 +1527,7 @@ class Document
15271527
bool m_loadEventFinished;
15281528

15291529
RefPtr<SerializedScriptValue> m_pendingStateObject;
1530-
std::chrono::steady_clock::time_point m_startTime;
1530+
MonotonicTime m_documentCreationTime;
15311531
bool m_overMinimumLayoutThreshold;
15321532

15331533
std::unique_ptr<ScriptRunner> m_scriptRunner;

Source/WebCore/page/ChromeClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class WEBCORE_EXPORT ChromeClient {
233233
virtual void didPreventDefaultForEvent() = 0;
234234
#endif
235235

236-
virtual Seconds eventThrottlingDelay() { return Seconds(0); };
236+
virtual Seconds eventThrottlingDelay() { return 0_s; };
237237

238238
#if PLATFORM(IOS)
239239
virtual void didReceiveMobileDocType(bool) = 0;

Source/WebCore/page/FrameView.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,9 +1398,9 @@ void FrameView::layout(bool allowSubtree)
13981398
}
13991399
}
14001400

1401-
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
1401+
#if !LOG_DISABLED
14021402
if (m_firstLayout && !frame().ownerElement())
1403-
printf("Elapsed time before first layout: %lld\n", document.elapsedTime().count());
1403+
LOG(Layout, "FrameView %p elapsed time before first layout: %.3fs\n", this, document.timeSinceDocumentCreation().value());
14041404
#endif
14051405
}
14061406

@@ -2437,9 +2437,9 @@ void FrameView::scrollOffsetChangedViaPlatformWidgetImpl(const ScrollOffset& old
24372437
void FrameView::scrollPositionChanged(const ScrollPosition& oldPosition, const ScrollPosition& newPosition)
24382438
{
24392439
Page* page = frame().page();
2440-
Seconds throttlingDelay = page ? page->chrome().client().eventThrottlingDelay() : Seconds(0);
2440+
Seconds throttlingDelay = page ? page->chrome().client().eventThrottlingDelay() : 0_s;
24412441

2442-
if (throttlingDelay == Seconds(0)) {
2442+
if (throttlingDelay == 0_s) {
24432443
m_delayedScrollEventTimer.stop();
24442444
sendScrollEvent();
24452445
} else if (!m_delayedScrollEventTimer.isActive())
@@ -2874,9 +2874,9 @@ void FrameView::convertSubtreeLayoutToFullLayout()
28742874

28752875
void FrameView::layoutTimerFired()
28762876
{
2877-
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
2877+
#if !LOG_DISABLED
28782878
if (!frame().document()->ownerElement())
2879-
printf("Layout timer fired at %lld\n", frame().document()->elapsedTime().count());
2879+
LOG(Layout, "FrameView %p layout timer fired at %.3fs", this, frame().document()->timeSinceDocumentCreation().value());
28802880
#endif
28812881
layout();
28822882
}
@@ -2901,17 +2901,18 @@ void FrameView::scheduleRelayout()
29012901
if (frame().ownerRenderer() && isInChildFrameWithFrameFlattening())
29022902
frame().ownerRenderer()->setNeedsLayout(MarkContainingBlockChain);
29032903

2904-
std::chrono::milliseconds delay = frame().document()->minimumLayoutDelay();
2905-
if (m_layoutTimer.isActive() && m_delayedLayout && !delay.count())
2904+
Seconds delay = frame().document()->minimumLayoutDelay();
2905+
if (m_layoutTimer.isActive() && m_delayedLayout && !delay)
29062906
unscheduleRelayout();
2907+
29072908
if (m_layoutTimer.isActive())
29082909
return;
29092910

2910-
m_delayedLayout = delay.count();
2911+
m_delayedLayout = delay.value();
29112912

2912-
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
2913+
#if !LOG_DISABLED
29132914
if (!frame().document()->ownerElement())
2914-
printf("Scheduling layout for %d\n", delay);
2915+
LOG(Layout, "FrameView %p scheduling layout for %.3fs", this, delay.value());
29152916
#endif
29162917

29172918
m_layoutTimer.startOneShot(delay);
@@ -2944,11 +2945,11 @@ void FrameView::scheduleRelayoutOfSubtree(RenderElement& newRelayoutRoot)
29442945
}
29452946

29462947
if (!layoutPending() && m_layoutSchedulingEnabled) {
2947-
std::chrono::milliseconds delay = renderView.document().minimumLayoutDelay();
2948+
Seconds delay = renderView.document().minimumLayoutDelay();
29482949
ASSERT(!newRelayoutRoot.container() || is<RenderView>(newRelayoutRoot.container()) || !newRelayoutRoot.container()->needsLayout());
29492950
m_layoutRoot = &newRelayoutRoot;
29502951
InspectorInstrumentation::didInvalidateLayout(frame());
2951-
m_delayedLayout = delay.count();
2952+
m_delayedLayout = delay.value();
29522953
m_layoutTimer.startOneShot(delay);
29532954
return;
29542955
}
@@ -3041,9 +3042,9 @@ void FrameView::unscheduleRelayout()
30413042
if (!m_layoutTimer.isActive())
30423043
return;
30433044

3044-
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
3045+
#if !LOG_DISABLED
30453046
if (!frame().document()->ownerElement())
3046-
printf("Layout timer unscheduled at %d\n", frame().document()->elapsedTime());
3047+
LOG(Layout, "FrameView %p layout timer unscheduled at %.3fs", this, frame().document()->timeSinceDocumentCreation().value());
30473048
#endif
30483049

30493050
m_layoutTimer.stop();

Source/WebCore/page/Settings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static const bool defaultSelectTrailingWhitespaceEnabled = false;
184184
// This amount of time must have elapsed before we will even consider scheduling a layout without a delay.
185185
// FIXME: For faster machines this value can really be lowered to 200. 250 is adequate, but a little high
186186
// for dual G5s. :)
187-
static const auto layoutScheduleThreshold = 250ms;
187+
static const Seconds layoutScheduleThreshold = 250_ms;
188188

189189
Settings::Settings(Page* page)
190190
: m_page(nullptr)
@@ -461,7 +461,7 @@ void Settings::setMinimumDOMTimerInterval(std::chrono::milliseconds interval)
461461
}
462462
}
463463

464-
void Settings::setLayoutInterval(std::chrono::milliseconds layoutInterval)
464+
void Settings::setLayoutInterval(Seconds layoutInterval)
465465
{
466466
// FIXME: It seems weird that this function may disregard the specified layout interval.
467467
// We should either expose layoutScheduleThreshold or better communicate this invariant.

0 commit comments

Comments
 (0)