Optimized CanvasGraphics_executeOperatorList 66% faster
This commit is contained in:
parent
d4a01f6034
commit
35e418c603
@ -394,6 +394,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
// Defines the time the executeOperatorList is going to be executing
|
// Defines the time the executeOperatorList is going to be executing
|
||||||
// before it stops and shedules a continue of execution.
|
// before it stops and shedules a continue of execution.
|
||||||
var EXECUTION_TIME = 15;
|
var EXECUTION_TIME = 15;
|
||||||
|
// Defines the number of steps before checking the execution time
|
||||||
|
var EXECUTION_STEPS = 10;
|
||||||
|
|
||||||
function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
|
function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
|
||||||
this.ctx = canvasCtx;
|
this.ctx = canvasCtx;
|
||||||
@ -726,18 +728,21 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
var argsArrayLen = argsArray.length;
|
var argsArrayLen = argsArray.length;
|
||||||
|
|
||||||
// Sometimes the OperatorList to execute is empty.
|
// Sometimes the OperatorList to execute is empty.
|
||||||
if (argsArrayLen == i) {
|
if (argsArrayLen === i) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
var endTime = Date.now() + EXECUTION_TIME;
|
var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
|
||||||
|
typeof continueCallback === 'function');
|
||||||
|
var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
|
||||||
|
var steps = 0;
|
||||||
|
|
||||||
var commonObjs = this.commonObjs;
|
var commonObjs = this.commonObjs;
|
||||||
var objs = this.objs;
|
var objs = this.objs;
|
||||||
var fnId;
|
var fnId;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (stepper && i === stepper.nextBreakPoint) {
|
if (stepper !== undefined && i === stepper.nextBreakPoint) {
|
||||||
stepper.breakIt(i, continueCallback);
|
stepper.breakIt(i, continueCallback);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -750,16 +755,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
var deps = argsArray[i];
|
var deps = argsArray[i];
|
||||||
for (var n = 0, nn = deps.length; n < nn; n++) {
|
for (var n = 0, nn = deps.length; n < nn; n++) {
|
||||||
var depObjId = deps[n];
|
var depObjId = deps[n];
|
||||||
var common = depObjId.substring(0, 2) == 'g_';
|
var common = depObjId[0] === 'g' && depObjId[1] === '_';
|
||||||
|
var objsPool = common ? commonObjs : objs;
|
||||||
|
|
||||||
// If the promise isn't resolved yet, add the continueCallback
|
// If the promise isn't resolved yet, add the continueCallback
|
||||||
// to the promise and bail out.
|
// to the promise and bail out.
|
||||||
if (!common && !objs.isResolved(depObjId)) {
|
if (!objsPool.isResolved(depObjId)) {
|
||||||
objs.get(depObjId, continueCallback);
|
objsPool.get(depObjId, continueCallback);
|
||||||
return i;
|
|
||||||
}
|
|
||||||
if (common && !commonObjs.isResolved(depObjId)) {
|
|
||||||
commonObjs.get(depObjId, continueCallback);
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -768,15 +770,18 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
i++;
|
i++;
|
||||||
|
|
||||||
// If the entire operatorList was executed, stop as were done.
|
// If the entire operatorList was executed, stop as were done.
|
||||||
if (i == argsArrayLen) {
|
if (i === argsArrayLen) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the execution took longer then a certain amount of time and
|
// If the execution took longer then a certain amount of time and
|
||||||
// `continueCallback` is specified, interrupt the execution.
|
// `continueCallback` is specified, interrupt the execution.
|
||||||
if (continueCallback && Date.now() > endTime) {
|
if (chunkOperations && ++steps > EXECUTION_STEPS) {
|
||||||
continueCallback();
|
if (Date.now() > endTime) {
|
||||||
return i;
|
continueCallback();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
steps = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the operatorList isn't executed completely yet OR the execution
|
// If the operatorList isn't executed completely yet OR the execution
|
||||||
|
Loading…
x
Reference in New Issue
Block a user