[Pkg-javascript-commits] [pdf.js] 37/207: Optimized CanvasGraphics_executeOperatorList 66% faster
David Prévot
taffit at moszumanska.debian.org
Mon Jul 28 15:36:27 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 35e418c603e5307bab705fc526ba9caebced43ba
Author: p01 <p01 at opera.com>
Date: Mon Jun 2 14:40:33 2014 +0200
Optimized CanvasGraphics_executeOperatorList 66% faster
---
src/display/canvas.js | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 22b0275..34b877a 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -394,6 +394,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// Defines the time the executeOperatorList is going to be executing
// before it stops and shedules a continue of execution.
var EXECUTION_TIME = 15;
+ // Defines the number of steps before checking the execution time
+ var EXECUTION_STEPS = 10;
function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
this.ctx = canvasCtx;
@@ -726,18 +728,21 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var argsArrayLen = argsArray.length;
// Sometimes the OperatorList to execute is empty.
- if (argsArrayLen == i) {
+ if (argsArrayLen === 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 objs = this.objs;
var fnId;
while (true) {
- if (stepper && i === stepper.nextBreakPoint) {
+ if (stepper !== undefined && i === stepper.nextBreakPoint) {
stepper.breakIt(i, continueCallback);
return i;
}
@@ -750,16 +755,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var deps = argsArray[i];
for (var n = 0, nn = deps.length; n < nn; 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
// to the promise and bail out.
- if (!common && !objs.isResolved(depObjId)) {
- objs.get(depObjId, continueCallback);
- return i;
- }
- if (common && !commonObjs.isResolved(depObjId)) {
- commonObjs.get(depObjId, continueCallback);
+ if (!objsPool.isResolved(depObjId)) {
+ objsPool.get(depObjId, continueCallback);
return i;
}
}
@@ -768,15 +770,18 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
i++;
// If the entire operatorList was executed, stop as were done.
- if (i == argsArrayLen) {
+ if (i === argsArrayLen) {
return i;
}
// If the execution took longer then a certain amount of time and
// `continueCallback` is specified, interrupt the execution.
- if (continueCallback && Date.now() > endTime) {
- continueCallback();
- return i;
+ if (chunkOperations && ++steps > EXECUTION_STEPS) {
+ if (Date.now() > endTime) {
+ continueCallback();
+ return i;
+ }
+ steps = 0;
}
// If the operatorList isn't executed completely yet OR the execution
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list