Skip to content

Commit

Permalink
Revert "Merge pull request scratchfoundation#1398 from cwillisf/fix-w…
Browse files Browse the repository at this point in the history
…arp"

This reverts commit 21c611b, reversing
changes made to 76af421. This puts the
"Flash 30 fix" code in the same state it was in at v461.
Christopher Willis-Ford committed Nov 5, 2018
1 parent 689f3c7 commit 72e4729
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/interpreter/Interpreter.as
Original file line number Diff line number Diff line change
@@ -221,21 +221,32 @@ public class Interpreter {
}

private const workTimeCheckIntervalFactor:Number = 1/3.0;
private var iterationCountEstimate: Number = 1; // start low to avoid appearance of hang
private const maxIterationCountSamples: uint = 10;
private var iterationCountSamples: Vector.<uint> = new <uint>[500]; // initial guess

private function addIterationCountSample(sample:uint):void {
// Exponential moving average: simulate N=10 with a=2/(N+1)=2/11
const alpha:Number = 2.0/11.0;
iterationCountEstimate += alpha * (sample - iterationCountEstimate);
iterationCountSamples.push(sample);
while (iterationCountSamples.length > maxIterationCountSamples) {
iterationCountSamples.shift();
}
}

private function getAverageIterationCount():Number {
var total:uint = 0;
for each (var sample:uint in iterationCountSamples) {
total += sample;
}
return Number(total) / iterationCountSamples.length;
}

public function stepThreads():void {
var workTime:int = (0.75 * 1000) / app.stage.frameRate; // work for up to 75% of one frame time
doRedraw = false;
startTime = currentMSecs = CachedTimer.getFreshTimer();
if (threads.length == 0) return;
var currentEstimate:Number = getAverageIterationCount();
var iterationCount:uint = 0;
var checkInterval:uint = Math.round(workTimeCheckIntervalFactor * iterationCountEstimate);
var checkInterval:uint = Math.round(workTimeCheckIntervalFactor * currentEstimate);
var checkCount:uint = 0;
while ((currentMSecs - startTime) < workTime) {
if (warpThread && (warpThread.block == null)) clearWarpBlock();
@@ -285,13 +296,15 @@ public class Interpreter {
}
}
yield = false;
var warpStartTimer:int = CachedTimer.getCachedTimer();
while (true) {
if (activeThread == warpThread) currentMSecs = CachedTimer.getFreshTimer();
if (activeThread == warpThread) currentMSecs = warpStartTimer;
evalCmd(activeThread.block);
if (yield) {
if (activeThread == warpThread) {
if ((currentMSecs - startTime) > warpMSecs) return;
yield = false;
warpStartTimer = CachedTimer.getFreshTimer();
continue;
} else return;
}

0 comments on commit 72e4729

Please sign in to comment.