optimized scheduler, reduced system calls to Date.now()

25 % speed-up for reporters, WARP and TURBO
pull/95/head
jmoenig 2020-12-18 18:28:15 +01:00
rodzic 8052149707
commit 3bc7f5270a
3 zmienionych plików z 20 dodań i 6 usunięć

Wyświetl plik

@ -3,10 +3,14 @@
## in development:
* **Notable Changes:**
* 25 % speed-up for reporters, WARP and TURBO
* re-enabled reporter drops in "key _ pressed?" input slot
* **Notable Fixes:**
* fixed keyboard formula entry for subtraction
### 2020-12-18
* threads: optimized scheduler, reduced system calls to Date.now(), 25 % speed-up for reporters, WARP and TURBO
### 2020-12-17
* blocks: added hook for caching variadic inputs
* blocks: refactored blockSequence() non-recursively

Wyświetl plik

@ -9,7 +9,7 @@
<script src="src/symbols.js?version=2020-10-07"></script>
<script src="src/widgets.js?version=2020-10-06"></script>
<script src="src/blocks.js?version=2020-12-17"></script>
<script src="src/threads.js?version=2020-12-16"></script>
<script src="src/threads.js?version=2020-12-18"></script>
<script src="src/objects.js?version=2020-12-16"></script>
<script src="src/gui.js?version=2020-12-15"></script>
<script src="src/paint.js?version=2020-05-17"></script>

Wyświetl plik

@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, Map,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, BLACK,
TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume*/
modules.threads = '2020-December-16';
modules.threads = '2020-December-18';
var ThreadManager;
var Process;
@ -583,7 +583,9 @@ function Process(topBlock, receiver, onComplete, yieldFirst) {
this.httpRequest = null;
this.isPaused = false;
this.pauseOffset = null;
this.currentTime = Date.now();
this.frameCount = 0;
this.stepFrameCount = 0;
this.yieldCount = 0;
this.exportResult = false;
this.onComplete = onComplete || null;
@ -626,13 +628,13 @@ Process.prototype.runStep = function (deadline) {
while (!this.readyToYield && !this.isInterrupted
&& this.context
&& (Date.now() - this.lastYield < this.timeout)
&& (this.currentTime - this.lastYield < this.timeout)
) {
// also allow pausing inside atomic steps - for PAUSE block primitive:
if (this.isPaused) {
return this.pauseStep();
}
if (deadline && (Date.now() > deadline)) {
if (deadline && (this.currentTime > deadline)) {
if (this.isAtomic &&
this.homeContext.receiver &&
this.homeContext.receiver.endWarp) {
@ -643,6 +645,7 @@ Process.prototype.runStep = function (deadline) {
this.evaluateContext();
}
this.stepFrameCount = 0;
this.yieldCount += 1;
this.lastYield = Date.now();
this.isFirstStep = false;
@ -708,7 +711,14 @@ Process.prototype.pauseStep = function () {
Process.prototype.evaluateContext = function () {
var exp = this.context.expression;
this.frameCount += 1;
this.stepFrameCount += 1;
if (this.stepFrameCount > 100) {
this.currentTime = Date.now();
this.stepFrameCount = 0;
}
if (this.context.tag === 'exit') {
this.expectReport();
}
@ -1158,7 +1168,7 @@ Process.prototype.evaluate = function (
if (context.expression instanceof ReporterBlockMorph) {
// auto-"warp" nested reporters
this.readyToYield = (Date.now() - this.lastYield > this.timeout);
this.readyToYield = (this.currentTime - this.lastYield > this.timeout);
}
// assign arguments to parameters
@ -1478,7 +1488,7 @@ Process.prototype.evaluateCustomBlock = function () {
runnable.parentContext = exit;
}
// auto-"warp" nested reporters
this.readyToYield = (Date.now() - this.lastYield > this.timeout);
this.readyToYield = (this.currentTime - this.lastYield > this.timeout);
} else {
// tag all "stop this block" blocks with the current
// procedureCount as exitTag, and mark all "report" blocks