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: ## in development:
* **Notable Changes:** * **Notable Changes:**
* 25 % speed-up for reporters, WARP and TURBO
* re-enabled reporter drops in "key _ pressed?" input slot * re-enabled reporter drops in "key _ pressed?" input slot
* **Notable Fixes:** * **Notable Fixes:**
* fixed keyboard formula entry for subtraction * 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 ### 2020-12-17
* blocks: added hook for caching variadic inputs * blocks: added hook for caching variadic inputs
* blocks: refactored blockSequence() non-recursively * 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/symbols.js?version=2020-10-07"></script>
<script src="src/widgets.js?version=2020-10-06"></script> <script src="src/widgets.js?version=2020-10-06"></script>
<script src="src/blocks.js?version=2020-12-17"></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/objects.js?version=2020-12-16"></script>
<script src="src/gui.js?version=2020-12-15"></script> <script src="src/gui.js?version=2020-12-15"></script>
<script src="src/paint.js?version=2020-05-17"></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, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, BLACK,
TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume*/ TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume*/
modules.threads = '2020-December-16'; modules.threads = '2020-December-18';
var ThreadManager; var ThreadManager;
var Process; var Process;
@ -583,7 +583,9 @@ function Process(topBlock, receiver, onComplete, yieldFirst) {
this.httpRequest = null; this.httpRequest = null;
this.isPaused = false; this.isPaused = false;
this.pauseOffset = null; this.pauseOffset = null;
this.currentTime = Date.now();
this.frameCount = 0; this.frameCount = 0;
this.stepFrameCount = 0;
this.yieldCount = 0; this.yieldCount = 0;
this.exportResult = false; this.exportResult = false;
this.onComplete = onComplete || null; this.onComplete = onComplete || null;
@ -626,13 +628,13 @@ Process.prototype.runStep = function (deadline) {
while (!this.readyToYield && !this.isInterrupted while (!this.readyToYield && !this.isInterrupted
&& this.context && this.context
&& (Date.now() - this.lastYield < this.timeout) && (this.currentTime - this.lastYield < this.timeout)
) { ) {
// also allow pausing inside atomic steps - for PAUSE block primitive: // also allow pausing inside atomic steps - for PAUSE block primitive:
if (this.isPaused) { if (this.isPaused) {
return this.pauseStep(); return this.pauseStep();
} }
if (deadline && (Date.now() > deadline)) { if (deadline && (this.currentTime > deadline)) {
if (this.isAtomic && if (this.isAtomic &&
this.homeContext.receiver && this.homeContext.receiver &&
this.homeContext.receiver.endWarp) { this.homeContext.receiver.endWarp) {
@ -643,6 +645,7 @@ Process.prototype.runStep = function (deadline) {
this.evaluateContext(); this.evaluateContext();
} }
this.stepFrameCount = 0;
this.yieldCount += 1; this.yieldCount += 1;
this.lastYield = Date.now(); this.lastYield = Date.now();
this.isFirstStep = false; this.isFirstStep = false;
@ -708,7 +711,14 @@ Process.prototype.pauseStep = function () {
Process.prototype.evaluateContext = function () { Process.prototype.evaluateContext = function () {
var exp = this.context.expression; var exp = this.context.expression;
this.frameCount += 1; this.frameCount += 1;
this.stepFrameCount += 1;
if (this.stepFrameCount > 100) {
this.currentTime = Date.now();
this.stepFrameCount = 0;
}
if (this.context.tag === 'exit') { if (this.context.tag === 'exit') {
this.expectReport(); this.expectReport();
} }
@ -1158,7 +1168,7 @@ Process.prototype.evaluate = function (
if (context.expression instanceof ReporterBlockMorph) { if (context.expression instanceof ReporterBlockMorph) {
// auto-"warp" nested reporters // auto-"warp" nested reporters
this.readyToYield = (Date.now() - this.lastYield > this.timeout); this.readyToYield = (this.currentTime - this.lastYield > this.timeout);
} }
// assign arguments to parameters // assign arguments to parameters
@ -1478,7 +1488,7 @@ Process.prototype.evaluateCustomBlock = function () {
runnable.parentContext = exit; runnable.parentContext = exit;
} }
// auto-"warp" nested reporters // auto-"warp" nested reporters
this.readyToYield = (Date.now() - this.lastYield > this.timeout); this.readyToYield = (this.currentTime - this.lastYield > this.timeout);
} else { } else {
// tag all "stop this block" blocks with the current // tag all "stop this block" blocks with the current
// procedureCount as exitTag, and mark all "report" blocks // procedureCount as exitTag, and mark all "report" blocks