Skip to content

Commit 12912e6

Browse files
committed
[MERGE #2940 @pleath] Modify redeferral heuristic and add a cap.
Merge pull request #2940 from pleath:redefercap Make the required inactive threshold grow exponentially (not linearly) with the number of previous compiles. Add a cap on the number of compiles (3 compiles, or 2 redeferrals, by default).
2 parents 5226df8 + 3ec0a24 commit 12912e6

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/Common/ConfigFlagsList.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ PHASE(All)
422422
#define DEFAULT_CONFIG_ExtendedErrorStackForTestHost (false)
423423
#define DEFAULT_CONFIG_ForceSplitScope (false)
424424
#define DEFAULT_CONFIG_DelayFullJITSmallFunc (0)
425-
425+
#define DEFAULT_CONFIG_RedeferralCap (3)
426426

427427
//Following determines inline thresholds
428428
#define DEFAULT_CONFIG_InlineThreshold (35) //Default start
@@ -1157,6 +1157,7 @@ FLAGNR(Number, ConstantArgumentInlineThreshold, "Maximum size in bytecodes of a
11571157
FLAGNR(Number, RecursiveInlineThreshold, "Maximum size in bytecodes of an inline candidate to inline recursively", DEFAULT_CONFIG_RecursiveInlineThreshold)
11581158
FLAGNR(Number, RecursiveInlineDepthMax, "Maximum depth of a recursive inline call", DEFAULT_CONFIG_RecursiveInlineDepthMax)
11591159
FLAGNR(Number, RecursiveInlineDepthMin, "Maximum depth of a recursive inline call", DEFAULT_CONFIG_RecursiveInlineDepthMin)
1160+
FLAGNR(Number, RedeferralCap, "Number of compilations beyond which we stop redeferring a function", DEFAULT_CONFIG_RedeferralCap)
11601161
FLAGNR(Number, Loop , "Number of times to execute the script (useful for profiling short benchmarks and finding leaks)", DEFAULT_CONFIG_Loop)
11611162
FLAGRA(Number, LoopInterpretCount , lic, "Number of times loop has to be interpreted before JIT Loop body", DEFAULT_CONFIG_LoopInterpretCount)
11621163
FLAGNR(Number, LoopProfileIterations , "Number of iterations of a loop that must be profiled before jitting the loop body", DEFAULT_CONFIG_LoopProfileIterations)

lib/Runtime/Base/FunctionBody.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,23 @@ namespace Js
853853

854854
if (!PHASE_FORCE(Js::RedeferralPhase, this) && !PHASE_STRESS(Js::RedeferralPhase, this))
855855
{
856-
uint tmpThreshold;
857-
auto fn = [&](){ tmpThreshold = 0xFFFFFFFF; };
858-
tmpThreshold = UInt32Math::Mul(inactiveThreshold, this->GetCompileCount(), fn);
859-
if (this->GetInactiveCount() < tmpThreshold)
856+
uint compileCount = this->GetCompileCount();
857+
if (compileCount >= (uint)CONFIG_FLAG(RedeferralCap))
858+
{
859+
return false;
860+
}
861+
// Redeferral threshold is k^x, where x is the number of previous compiles.
862+
bool overflow = false;
863+
uint currentThreshold = inactiveThreshold;
864+
if (compileCount > 1)
865+
{
866+
currentThreshold = JavascriptNumber::DirectPowIntInt(&overflow, inactiveThreshold, compileCount);
867+
}
868+
if (overflow)
869+
{
870+
currentThreshold = 0xFFFFFFFF;
871+
}
872+
if (this->GetInactiveCount() < currentThreshold)
860873
{
861874
return false;
862875
}

0 commit comments

Comments
 (0)