Changeset 201836 in webkit


Ignore:
Timestamp:
Jun 8, 2016 3:22:49 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

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

Source/JavaScriptCore:

Patch by Benjamin Poulain <bpoulain@apple.com> 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 <benjamin@webkit.org> on 2016-06-08
Reviewed by Filip Pizlo.

  • Scripts/run-jsc-stress-tests:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r201834 r201836  
     12016-06-08  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        [JSC] Change some parameters based on a random search
     4        https://bugs.webkit.org/show_bug.cgi?id=158514
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Over the weekend, I left an iMac running the JSC benchmarks
     9        while changing a bunch of parameters.
     10
     11        The parameters were changed randomly, with a random deviation
     12        from the original value.
     13        To converge toward good values, the range was subject
     14        to exponential annealing over time.
     15
     16        The values in this patch is the best outcome my iMac could
     17        find over the weekend. It is about 1% better on the Haswell
     18        machines I tested.
     19
     20        * bytecode/CodeBlock.cpp:
     21        (JSC::CodeBlock::optimizationThresholdScalingFactor):
     22        * runtime/Options.h:
     23
    1242016-06-08  Gavin Barraclough  <barraclough@apple.com>
    225
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r201668 r201836  
    36173617double CodeBlock::optimizationThresholdScalingFactor()
    36183618{
    3619     // This expression arises from doing a least-squares fit of
     3619    // We want a good threshold based on the instruction count.
     3620    // Here, we are trying to optimize the following formula:
     3621    //     F[x_] =: a * Sqrt[x + b] + Abs[c * x] + d
    36203622    //
    3621     // F[x_] =: a * Sqrt[x + b] + Abs[c * x] + d
    3622     //
    3623     // against the data points:
    3624     //
    3625     //    x       F[x_]
    3626     //    10       0.9          (smallest reasonable code block)
    3627     //   200       1.0          (typical small-ish code block)
    3628     //   320       1.2          (something I saw in 3d-cube that I wanted to optimize)
    3629     //  1268       5.0          (something I saw in 3d-cube that I didn't want to optimize)
    3630     //  4000       5.5          (random large size, used to cause the function to converge to a shallow curve of some sort)
    3631     // 10000       6.0          (similar to above)
    3632     //
    3633     // I achieve the minimization using the following Mathematica code:
    3634     //
    3635     // MyFunctionTemplate[x_, a_, b_, c_, d_] := a*Sqrt[x + b] + Abs[c*x] + d
    3636     //
    3637     // samples = {{10, 0.9}, {200, 1}, {320, 1.2}, {1268, 5}, {4000, 5.5}, {10000, 6}}
    3638     //
    3639     // solution =
    3640     //     Minimize[Plus @@ ((MyFunctionTemplate[#[[1]], a, b, c, d] - #[[2]])^2 & /@ samples),
    3641     //         {a, b, c, d}][[2]]
    3642     //
    3643     // And the code below (to initialize a, b, c, d) is generated by:
    3644     //
    3645     // Print["const double " <> ToString[#[[1]]] <> " = " <>
    3646     //     If[#[[2]] < 0.00001, "0.0", ToString[#[[2]]]] <> ";"] & /@ solution
    3647     //
    3648     // We've long known the following to be true:
    3649     // - Small code blocks are cheap to optimize and so we should do it sooner rather
    3650     //   than later.
    3651     // - Large code blocks are expensive to optimize and so we should postpone doing so,
    3652     //   and sometimes have a large enough threshold that we never optimize them.
    3653     // - The difference in cost is not totally linear because (a) just invoking the
    3654     //   DFG incurs some base cost and (b) for large code blocks there is enough slop
    3655     //   in the correlation between instruction count and the actual compilation cost
    3656     //   that for those large blocks, the instruction count should not have a strong
    3657     //   influence on our threshold.
    3658     //
    3659     // I knew the goals but I didn't know how to achieve them; so I picked an interesting
    3660     // example where the heuristics were right (code block in 3d-cube with instruction
    3661     // count 320, which got compiled early as it should have been) and one where they were
    3662     // totally wrong (code block in 3d-cube with instruction count 1268, which was expensive
    3663     // to compile and didn't run often enough to warrant compilation in my opinion), and
    3664     // then threw in additional data points that represented my own guess of what our
    3665     // heuristics should do for some round-numbered examples.
    3666     //
    3667     // The expression to which I decided to fit the data arose because I started with an
    3668     // affine function, and then did two things: put the linear part in an Abs to ensure
    3669     // that the fit didn't end up choosing a negative value of c (which would result in
    3670     // the function turning over and going negative for large x) and I threw in a Sqrt
    3671     // term because Sqrt represents my intution that the function should be more sensitive
    3672     // to small changes in small values of x, but less sensitive when x gets large.
    3673    
    3674     // Note that the current fit essentially eliminates the linear portion of the
    3675     // expression (c == 0.0).
    3676     const double a = 0.061504;
    3677     const double b = 1.02406;
    3678     const double c = 0.0;
    3679     const double d = 0.825914;
     3623    // The parameters were chosen by testing random values
     3624    // between 1 and 2 and keeping the best combination.
     3625    const double a = Options::optimizationThresholdScalingFactorA();
     3626    const double b = Options::optimizationThresholdScalingFactorB();
     3627    const double c = Options::optimizationThresholdScalingFactorC();
     3628    const double d = Options::optimizationThresholdScalingFactorD();
    36803629   
    36813630    double instructionCount = this->instructionCount();
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r201783 r201836  
    254254    v(double, jitPolicyScale, 1.0, Normal, "scale JIT thresholds to this specified ratio between 0.0 (compile ASAP) and 1.0 (compile like normal).") \
    255255    v(bool, forceEagerCompilation, false, Normal, nullptr) \
    256     v(int32, thresholdForJITAfterWarmUp, 500, Normal, nullptr) \
    257     v(int32, thresholdForJITSoon, 100, Normal, nullptr) \
    258     \
    259     v(int32, thresholdForOptimizeAfterWarmUp, 1000, Normal, nullptr) \
    260     v(int32, thresholdForOptimizeAfterLongWarmUp, 1000, Normal, nullptr) \
    261     v(int32, thresholdForOptimizeSoon, 1000, Normal, nullptr) \
    262     v(int32, executionCounterIncrementForLoop, 1, Normal, nullptr) \
    263     v(int32, executionCounterIncrementForEntry, 15, Normal, nullptr) \
    264     \
    265     v(int32, thresholdForFTLOptimizeAfterWarmUp, 100000, Normal, nullptr) \
    266     v(int32, thresholdForFTLOptimizeSoon, 1000, Normal, nullptr) \
    267     v(int32, ftlTierUpCounterIncrementForLoop, 1, Normal, nullptr) \
    268     v(int32, ftlTierUpCounterIncrementForReturn, 15, Normal, nullptr) \
     256    v(int32, thresholdForJITAfterWarmUp, 373, Normal, nullptr) \
     257    v(int32, thresholdForJITSoon, 169, Normal, nullptr) \
     258    \
     259    v(int32, thresholdForOptimizeAfterWarmUp, 511, Normal, nullptr) \
     260    v(int32, thresholdForOptimizeAfterLongWarmUp, 885, Normal, nullptr) \
     261    v(int32, thresholdForOptimizeSoon, 853, Normal, nullptr) \
     262    v(int32, executionCounterIncrementForLoop, 2, Normal, nullptr) \
     263    v(int32, executionCounterIncrementForEntry, 28, Normal, nullptr) \
     264    \
     265    v(int32, thresholdForFTLOptimizeAfterWarmUp, 99566, Normal, nullptr) \
     266    v(int32, thresholdForFTLOptimizeSoon, 1566, Normal, nullptr) \
     267    v(int32, ftlTierUpCounterIncrementForLoop, 6, Normal, nullptr) \
     268    v(int32, ftlTierUpCounterIncrementForReturn, 13, Normal, nullptr) \
    269269    v(unsigned, ftlOSREntryFailureCountForReoptimization, 15, Normal, nullptr) \
    270270    v(unsigned, ftlOSREntryRetryThreshold, 100, Normal, nullptr) \
    271271    \
    272     v(int32, evalThresholdMultiplier, 10, Normal, nullptr) \
     272    v(double, optimizationThresholdScalingFactorA, 0.1785461740514816, Normal, nullptr) \
     273    v(double, optimizationThresholdScalingFactorB, 1.2691392484494950, Normal, nullptr) \
     274    v(double, optimizationThresholdScalingFactorC, 0.0003675505121227, Normal, nullptr) \
     275    v(double, optimizationThresholdScalingFactorD, 1.5838284192987762, Normal, nullptr) \
     276    \
     277    v(int32, evalThresholdMultiplier, 8, Normal, nullptr) \
    273278    v(unsigned, maximumEvalCacheableSourceLength, 256, Normal, nullptr) \
    274279    \
  • trunk/Tools/ChangeLog

    r201821 r201836  
     12016-06-08  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        [JSC] Change some parameters based on a random search
     4        https://bugs.webkit.org/show_bug.cgi?id=158514
     5
     6        Reviewed by Filip Pizlo.
     7
     8        * Scripts/run-jsc-stress-tests:
     9
    1102016-06-08  Aakash Jain  <aakash_jain@apple.com>
    211
  • trunk/Tools/Scripts/run-jsc-stress-tests

    r201618 r201836  
    429429BASE_OPTIONS = ["--useFTLJIT=false", "--useFunctionDotArguments=true"]
    430430EAGER_OPTIONS = ["--thresholdForJITAfterWarmUp=10", "--thresholdForJITSoon=10", "--thresholdForOptimizeAfterWarmUp=20", "--thresholdForOptimizeAfterLongWarmUp=20", "--thresholdForOptimizeSoon=20", "--thresholdForFTLOptimizeAfterWarmUp=20", "--thresholdForFTLOptimizeSoon=20", "--maximumEvalCacheableSourceLength=150000"]
    431 NO_CJIT_OPTIONS = ["--useConcurrentJIT=false", "--thresholdForJITAfterWarmUp=100"]
     431NO_CJIT_OPTIONS = ["--useConcurrentJIT=false", "--thresholdForJITAfterWarmUp=100", "--thresholdForJITSoon=100", "--thresholdForOptimizeAfterWarmUp=1000", "--thresholdForOptimizeAfterLongWarmUp=1000", "--thresholdForOptimizeSoon=1000", "--executionCounterIncrementForLoop=1", "--executionCounterIncrementForEntry=15", "--thresholdForFTLOptimizeAfterWarmUp=100000", "--thresholdForFTLOptimizeSoon=1000", "--ftlTierUpCounterIncrementForLoop=1", "--ftlTierUpCounterIncrementForReturn=15", "--evalThresholdMultiplier=10", "--optimizationThresholdScalingFactorA=0.061504", "--optimizationThresholdScalingFactorB=1.02406", "--optimizationThresholdScalingFactorC=0.0", "--optimizationThresholdScalingFactorD=0.825914"]
    432432FTL_OPTIONS = ["--useFTLJIT=true"]
    433433
Note: See TracChangeset for help on using the changeset viewer.