Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce usage of Date.now() in src/core/worker.js #10608

Merged
merged 2 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
*/

import {
arrayByteLength, arraysToBytes, assert, createPromiseCapability, info,
InvalidPDFException, MissingPDFException, PasswordException,
setVerbosityLevel, UnexpectedResponseException, UnknownErrorException,
UNSUPPORTED_FEATURES, warn
arrayByteLength, arraysToBytes, assert, createPromiseCapability,
getVerbosityLevel, info, InvalidPDFException, MissingPDFException,
PasswordException, setVerbosityLevel, UnexpectedResponseException,
UnknownErrorException, UNSUPPORTED_FEATURES, VerbosityLevel, warn
} from '../shared/util';
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
import isNodeJS from '../shared/is_node';
Expand Down Expand Up @@ -222,6 +222,7 @@ var WorkerMessageHandler = {
var terminated = false;
var cancelXHRs = null;
var WorkerTasks = [];
const verbosity = getVerbosityLevel();

let apiVersion = docParams.apiVersion;
let workerVersion =
Expand Down Expand Up @@ -578,8 +579,9 @@ var WorkerMessageHandler = {
var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
startWorkerTask(task);

var pageNum = pageIndex + 1;
var start = Date.now();
// NOTE: Keep this condition in sync with the `info` helper function.
const start = (verbosity >= VerbosityLevel.INFOS ? Date.now() : 0);

// Pre compile the pdf page and fetch the fonts/images.
page.getOperatorList({
handler,
Expand All @@ -589,8 +591,10 @@ var WorkerMessageHandler = {
}).then(function(operatorList) {
finishWorkerTask(task);

info('page=' + pageNum + ' - getOperatorList: time=' +
(Date.now() - start) + 'ms, len=' + operatorList.totalLength);
if (start) {
info(`page=${pageIndex + 1} - getOperatorList: time=` +
`${Date.now() - start}ms, len=${operatorList.totalLength}`);
}
}, function(e) {
finishWorkerTask(task);
if (task.terminated) {
Expand Down Expand Up @@ -626,7 +630,7 @@ var WorkerMessageHandler = {
}

handler.send('PageError', {
pageNum,
pageIndex,
error: wrappedException,
intent: data.intent,
});
Expand All @@ -643,8 +647,9 @@ var WorkerMessageHandler = {
var task = new WorkerTask('GetTextContent: page ' + pageIndex);
startWorkerTask(task);

var pageNum = pageIndex + 1;
var start = Date.now();
// NOTE: Keep this condition in sync with the `info` helper function.
const start = (verbosity >= VerbosityLevel.INFOS ? Date.now() : 0);

page.extractTextContent({
handler,
task,
Expand All @@ -654,8 +659,10 @@ var WorkerMessageHandler = {
}).then(function() {
finishWorkerTask(task);

info('text indexing: page=' + pageNum + ' - time=' +
(Date.now() - start) + 'ms');
if (start) {
info(`page=${pageIndex + 1} - getTextContent: time=` +
`${Date.now() - start}ms`);
}
sink.close();
}, function (reason) {
finishWorkerTask(task);
Expand Down
17 changes: 8 additions & 9 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
/* eslint no-var: error */

import {
assert, createPromiseCapability, deprecated, getVerbosityLevel, info,
InvalidPDFException, isArrayBuffer, isSameOrigin, MissingPDFException,
NativeImageDecoding, PasswordException, setVerbosityLevel, shadow,
stringToBytes, UnexpectedResponseException, UnknownErrorException,
unreachable, URL, warn
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
isArrayBuffer, isSameOrigin, MissingPDFException, NativeImageDecoding,
PasswordException, setVerbosityLevel, shadow, stringToBytes,
UnexpectedResponseException, UnknownErrorException, unreachable, URL, warn
} from '../shared/util';
import {
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, loadScript,
PageViewport, RenderingCancelledException, StatTimer
deprecated, DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer,
loadScript, PageViewport, RenderingCancelledException, StatTimer
} from './display_utils';
import { FontFaceObject, FontLoader } from './font_loader';
import { apiCompatibilityParams } from './api_compatibility';
Expand Down Expand Up @@ -2028,11 +2027,11 @@ class WorkerTransport {
return; // Ignore any pending requests if the worker was terminated.
}

const page = this.pageCache[data.pageNum - 1];
const page = this.pageCache[data.pageIndex];
const intentState = page.intentStates[data.intent];

if (intentState.displayReadyCapability) {
intentState.displayReadyCapability.reject(data.error);
intentState.displayReadyCapability.reject(new Error(data.error));
} else {
throw new Error(data.error);
}
Expand Down
6 changes: 6 additions & 0 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ function loadScript(src) {
});
}

// Deprecated API function -- display regardless of the `verbosity` setting.
function deprecated(details) {
console.log('Deprecated API usage: ' + details);
}

export {
PageViewport,
RenderingCancelledException,
Expand All @@ -492,4 +497,5 @@ export {
isFetchSupported,
isValidFetchUrl,
loadScript,
deprecated,
};
6 changes: 0 additions & 6 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,6 @@ function warn(msg) {
}
}

// Deprecated API function -- display regardless of the `verbosity` setting.
function deprecated(details) {
console.log('Deprecated API usage: ' + details);
}

function unreachable(msg) {
throw new Error(msg);
}
Expand Down Expand Up @@ -929,7 +924,6 @@ export {
bytesToString,
createPromiseCapability,
createObjectURL,
deprecated,
getVerbosityLevel,
info,
isArrayBuffer,
Expand Down