<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[201836] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/201836">201836</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-06-08 15:22:49 -0700 (Wed, 08 Jun 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[JSC] Change some parameters based on a random search
https://bugs.webkit.org/show_bug.cgi?id=158514

Source/JavaScriptCore:

Patch by Benjamin Poulain &lt;bpoulain@apple.com&gt; on 2016-06-08
Reviewed by Filip Pizlo.

Over the weekend, I left an iMac running the JSC benchmarks
while changing a bunch of parameters.

The parameters were changed randomly, with a random deviation
from the original value.
To converge toward good values, the range was subject
to exponential annealing over time.

The values in this patch is the best outcome my iMac could
find over the weekend. It is about 1% better on the Haswell
machines I tested.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::optimizationThresholdScalingFactor):
* runtime/Options.h:

Tools:

Patch by Benjamin Poulain &lt;benjamin@webkit.org&gt; on 2016-06-08
Reviewed by Filip Pizlo.

* Scripts/run-jsc-stress-tests:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeCodeBlockcpp">trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeOptionsh">trunk/Source/JavaScriptCore/runtime/Options.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptsrunjscstresstests">trunk/Tools/Scripts/run-jsc-stress-tests</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (201835 => 201836)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-06-08 22:14:55 UTC (rev 201835)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-06-08 22:22:49 UTC (rev 201836)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-06-08  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+        [JSC] Change some parameters based on a random search
+        https://bugs.webkit.org/show_bug.cgi?id=158514
+
+        Reviewed by Filip Pizlo.
+
+        Over the weekend, I left an iMac running the JSC benchmarks
+        while changing a bunch of parameters.
+
+        The parameters were changed randomly, with a random deviation
+        from the original value.
+        To converge toward good values, the range was subject
+        to exponential annealing over time.
+
+        The values in this patch is the best outcome my iMac could
+        find over the weekend. It is about 1% better on the Haswell
+        machines I tested.
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::optimizationThresholdScalingFactor):
+        * runtime/Options.h:
+
</ins><span class="cx"> 2016-06-08  Gavin Barraclough  &lt;barraclough@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove removeDirect
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeCodeBlockcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp (201835 => 201836)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp        2016-06-08 22:14:55 UTC (rev 201835)
+++ trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp        2016-06-08 22:22:49 UTC (rev 201836)
</span><span class="lines">@@ -3616,68 +3616,17 @@
</span><span class="cx"> 
</span><span class="cx"> double CodeBlock::optimizationThresholdScalingFactor()
</span><span class="cx"> {
</span><del>-    // This expression arises from doing a least-squares fit of
</del><ins>+    // We want a good threshold based on the instruction count.
+    // Here, we are trying to optimize the following formula:
+    //     F[x_] =: a * Sqrt[x + b] + Abs[c * x] + d
</ins><span class="cx">     //
</span><del>-    // F[x_] =: a * Sqrt[x + b] + Abs[c * x] + d
-    //
-    // against the data points:
-    //
-    //    x       F[x_]
-    //    10       0.9          (smallest reasonable code block)
-    //   200       1.0          (typical small-ish code block)
-    //   320       1.2          (something I saw in 3d-cube that I wanted to optimize)
-    //  1268       5.0          (something I saw in 3d-cube that I didn't want to optimize)
-    //  4000       5.5          (random large size, used to cause the function to converge to a shallow curve of some sort)
-    // 10000       6.0          (similar to above)
-    //
-    // I achieve the minimization using the following Mathematica code:
-    //
-    // MyFunctionTemplate[x_, a_, b_, c_, d_] := a*Sqrt[x + b] + Abs[c*x] + d
-    //
-    // samples = {{10, 0.9}, {200, 1}, {320, 1.2}, {1268, 5}, {4000, 5.5}, {10000, 6}}
-    //
-    // solution = 
-    //     Minimize[Plus @@ ((MyFunctionTemplate[#[[1]], a, b, c, d] - #[[2]])^2 &amp; /@ samples),
-    //         {a, b, c, d}][[2]]
-    //
-    // And the code below (to initialize a, b, c, d) is generated by:
-    //
-    // Print[&quot;const double &quot; &lt;&gt; ToString[#[[1]]] &lt;&gt; &quot; = &quot; &lt;&gt;
-    //     If[#[[2]] &lt; 0.00001, &quot;0.0&quot;, ToString[#[[2]]]] &lt;&gt; &quot;;&quot;] &amp; /@ solution
-    //
-    // We've long known the following to be true:
-    // - Small code blocks are cheap to optimize and so we should do it sooner rather
-    //   than later.
-    // - Large code blocks are expensive to optimize and so we should postpone doing so,
-    //   and sometimes have a large enough threshold that we never optimize them.
-    // - The difference in cost is not totally linear because (a) just invoking the
-    //   DFG incurs some base cost and (b) for large code blocks there is enough slop
-    //   in the correlation between instruction count and the actual compilation cost
-    //   that for those large blocks, the instruction count should not have a strong
-    //   influence on our threshold.
-    //
-    // I knew the goals but I didn't know how to achieve them; so I picked an interesting
-    // example where the heuristics were right (code block in 3d-cube with instruction
-    // count 320, which got compiled early as it should have been) and one where they were
-    // totally wrong (code block in 3d-cube with instruction count 1268, which was expensive
-    // to compile and didn't run often enough to warrant compilation in my opinion), and
-    // then threw in additional data points that represented my own guess of what our
-    // heuristics should do for some round-numbered examples.
-    //
-    // The expression to which I decided to fit the data arose because I started with an
-    // affine function, and then did two things: put the linear part in an Abs to ensure
-    // that the fit didn't end up choosing a negative value of c (which would result in
-    // the function turning over and going negative for large x) and I threw in a Sqrt
-    // term because Sqrt represents my intution that the function should be more sensitive
-    // to small changes in small values of x, but less sensitive when x gets large.
</del><ins>+    // The parameters were chosen by testing random values
+    // between 1 and 2 and keeping the best combination.
+    const double a = Options::optimizationThresholdScalingFactorA();
+    const double b = Options::optimizationThresholdScalingFactorB();
+    const double c = Options::optimizationThresholdScalingFactorC();
+    const double d = Options::optimizationThresholdScalingFactorD();
</ins><span class="cx">     
</span><del>-    // Note that the current fit essentially eliminates the linear portion of the
-    // expression (c == 0.0).
-    const double a = 0.061504;
-    const double b = 1.02406;
-    const double c = 0.0;
-    const double d = 0.825914;
-    
</del><span class="cx">     double instructionCount = this-&gt;instructionCount();
</span><span class="cx">     
</span><span class="cx">     ASSERT(instructionCount); // Make sure this is called only after we have an instruction stream; otherwise it'll just return the value of d, which makes no sense.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeOptionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Options.h (201835 => 201836)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Options.h        2016-06-08 22:14:55 UTC (rev 201835)
+++ trunk/Source/JavaScriptCore/runtime/Options.h        2016-06-08 22:22:49 UTC (rev 201836)
</span><span class="lines">@@ -253,23 +253,28 @@
</span><span class="cx">     \
</span><span class="cx">     v(double, jitPolicyScale, 1.0, Normal, &quot;scale JIT thresholds to this specified ratio between 0.0 (compile ASAP) and 1.0 (compile like normal).&quot;) \
</span><span class="cx">     v(bool, forceEagerCompilation, false, Normal, nullptr) \
</span><del>-    v(int32, thresholdForJITAfterWarmUp, 500, Normal, nullptr) \
-    v(int32, thresholdForJITSoon, 100, Normal, nullptr) \
</del><ins>+    v(int32, thresholdForJITAfterWarmUp, 373, Normal, nullptr) \
+    v(int32, thresholdForJITSoon, 169, Normal, nullptr) \
</ins><span class="cx">     \
</span><del>-    v(int32, thresholdForOptimizeAfterWarmUp, 1000, Normal, nullptr) \
-    v(int32, thresholdForOptimizeAfterLongWarmUp, 1000, Normal, nullptr) \
-    v(int32, thresholdForOptimizeSoon, 1000, Normal, nullptr) \
-    v(int32, executionCounterIncrementForLoop, 1, Normal, nullptr) \
-    v(int32, executionCounterIncrementForEntry, 15, Normal, nullptr) \
</del><ins>+    v(int32, thresholdForOptimizeAfterWarmUp, 511, Normal, nullptr) \
+    v(int32, thresholdForOptimizeAfterLongWarmUp, 885, Normal, nullptr) \
+    v(int32, thresholdForOptimizeSoon, 853, Normal, nullptr) \
+    v(int32, executionCounterIncrementForLoop, 2, Normal, nullptr) \
+    v(int32, executionCounterIncrementForEntry, 28, Normal, nullptr) \
</ins><span class="cx">     \
</span><del>-    v(int32, thresholdForFTLOptimizeAfterWarmUp, 100000, Normal, nullptr) \
-    v(int32, thresholdForFTLOptimizeSoon, 1000, Normal, nullptr) \
-    v(int32, ftlTierUpCounterIncrementForLoop, 1, Normal, nullptr) \
-    v(int32, ftlTierUpCounterIncrementForReturn, 15, Normal, nullptr) \
</del><ins>+    v(int32, thresholdForFTLOptimizeAfterWarmUp, 99566, Normal, nullptr) \
+    v(int32, thresholdForFTLOptimizeSoon, 1566, Normal, nullptr) \
+    v(int32, ftlTierUpCounterIncrementForLoop, 6, Normal, nullptr) \
+    v(int32, ftlTierUpCounterIncrementForReturn, 13, Normal, nullptr) \
</ins><span class="cx">     v(unsigned, ftlOSREntryFailureCountForReoptimization, 15, Normal, nullptr) \
</span><span class="cx">     v(unsigned, ftlOSREntryRetryThreshold, 100, Normal, nullptr) \
</span><span class="cx">     \
</span><del>-    v(int32, evalThresholdMultiplier, 10, Normal, nullptr) \
</del><ins>+    v(double, optimizationThresholdScalingFactorA, 0.1785461740514816, Normal, nullptr) \
+    v(double, optimizationThresholdScalingFactorB, 1.2691392484494950, Normal, nullptr) \
+    v(double, optimizationThresholdScalingFactorC, 0.0003675505121227, Normal, nullptr) \
+    v(double, optimizationThresholdScalingFactorD, 1.5838284192987762, Normal, nullptr) \
+    \
+    v(int32, evalThresholdMultiplier, 8, Normal, nullptr) \
</ins><span class="cx">     v(unsigned, maximumEvalCacheableSourceLength, 256, Normal, nullptr) \
</span><span class="cx">     \
</span><span class="cx">     v(bool, randomizeExecutionCountsBetweenCheckpoints, false, Normal, nullptr) \
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (201835 => 201836)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-06-08 22:14:55 UTC (rev 201835)
+++ trunk/Tools/ChangeLog        2016-06-08 22:22:49 UTC (rev 201836)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2016-06-08  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
+
+        [JSC] Change some parameters based on a random search
+        https://bugs.webkit.org/show_bug.cgi?id=158514
+
+        Reviewed by Filip Pizlo.
+
+        * Scripts/run-jsc-stress-tests:
+
</ins><span class="cx"> 2016-06-08  Aakash Jain  &lt;aakash_jain@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         tests fail if display sleeps while run-webkit-tests is running
</span></span></pre></div>
<a id="trunkToolsScriptsrunjscstresstests"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/run-jsc-stress-tests (201835 => 201836)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/run-jsc-stress-tests        2016-06-08 22:14:55 UTC (rev 201835)
+++ trunk/Tools/Scripts/run-jsc-stress-tests        2016-06-08 22:22:49 UTC (rev 201836)
</span><span class="lines">@@ -428,7 +428,7 @@
</span><span class="cx"> 
</span><span class="cx"> BASE_OPTIONS = [&quot;--useFTLJIT=false&quot;, &quot;--useFunctionDotArguments=true&quot;]
</span><span class="cx"> EAGER_OPTIONS = [&quot;--thresholdForJITAfterWarmUp=10&quot;, &quot;--thresholdForJITSoon=10&quot;, &quot;--thresholdForOptimizeAfterWarmUp=20&quot;, &quot;--thresholdForOptimizeAfterLongWarmUp=20&quot;, &quot;--thresholdForOptimizeSoon=20&quot;, &quot;--thresholdForFTLOptimizeAfterWarmUp=20&quot;, &quot;--thresholdForFTLOptimizeSoon=20&quot;, &quot;--maximumEvalCacheableSourceLength=150000&quot;]
</span><del>-NO_CJIT_OPTIONS = [&quot;--useConcurrentJIT=false&quot;, &quot;--thresholdForJITAfterWarmUp=100&quot;]
</del><ins>+NO_CJIT_OPTIONS = [&quot;--useConcurrentJIT=false&quot;, &quot;--thresholdForJITAfterWarmUp=100&quot;, &quot;--thresholdForJITSoon=100&quot;, &quot;--thresholdForOptimizeAfterWarmUp=1000&quot;, &quot;--thresholdForOptimizeAfterLongWarmUp=1000&quot;, &quot;--thresholdForOptimizeSoon=1000&quot;, &quot;--executionCounterIncrementForLoop=1&quot;, &quot;--executionCounterIncrementForEntry=15&quot;, &quot;--thresholdForFTLOptimizeAfterWarmUp=100000&quot;, &quot;--thresholdForFTLOptimizeSoon=1000&quot;, &quot;--ftlTierUpCounterIncrementForLoop=1&quot;, &quot;--ftlTierUpCounterIncrementForReturn=15&quot;, &quot;--evalThresholdMultiplier=10&quot;, &quot;--optimizationThresholdScalingFactorA=0.061504&quot;, &quot;--optimizationThresholdScalingFactorB=1.02406&quot;, &quot;--optimizationThresholdScalingFactorC=0.0&quot;, &quot;--optimizationThresholdScalingFactorD=0.825914&quot;]
</ins><span class="cx"> FTL_OPTIONS = [&quot;--useFTLJIT=true&quot;]
</span><span class="cx"> 
</span><span class="cx"> $runlist = []
</span></span></pre>
</div>
</div>

</body>
</html>