+2016-03-01 Gavin Barraclough <barraclough@apple.com>
+
+ Timer alignment in separate web processes should not all sync up to the same point.
+ https://bugs.webkit.org/show_bug.cgi?id=154878
+
+ Reviewed by Chris Dumez.
+
+ For any given WebContent process it is desirable that timers are synchronized to a single
+ alignment point, but if all WebContent processes align to the same point then there may
+ be a thundering herd of processes waking up.
+
+ * page/DOMTimer.cpp:
+ (WebCore::DOMTimer::alignedFireTime):
+ - align to a randomized point.
+
2016-03-01 Alex Christensen <achristensen@webkit.org>
Reduce size of internal windows build output
#include <wtf/HashMap.h>
#include <wtf/MathExtras.h>
#include <wtf/NeverDestroyed.h>
+#include <wtf/RandomNumber.h>
#include <wtf/StdLibExtras.h>
#if PLATFORM(IOS)
double DOMTimer::alignedFireTime(double fireTime) const
{
- if (double alignmentInterval = scriptExecutionContext()->timerAlignmentInterval(m_nestingLevel >= maxTimerNestingLevel))
- return ceil(fireTime / alignmentInterval) * alignmentInterval;
+ if (double alignmentInterval = scriptExecutionContext()->timerAlignmentInterval(m_nestingLevel >= maxTimerNestingLevel)) {
+ // Don't mess with zero-delay timers.
+ if (!fireTime)
+ return fireTime;
+ static const double randomizedAlignment = randomNumber();
+ // Force alignment to randomizedAlignment fraction of the way between alignemntIntervals, e.g.
+ // if alignmentInterval is 10 and randomizedAlignment is 0.3 this will align to 3, 13, 23, ...
+ return (ceil(fireTime / alignmentInterval - randomizedAlignment) + randomizedAlignment) * alignmentInterval;
+ }
return fireTime;
}