Skip to content

Commit 3a8318a

Browse files
Merge pull request #14359 from Snuffleupagus/PAUSE_EAGER_PAGE_INIT
Avoid overloading the worker-thread during eager page initialization in the viewer (PR 11263 follow-up)
2 parents a6dd39b + 90472e5 commit 3a8318a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

web/base_viewer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const DEFAULT_CACHE_SIZE = 10;
5757
const PagesCountLimit = {
5858
FORCE_SCROLL_MODE_PAGE: 15000,
5959
FORCE_LAZY_PAGE_INIT: 7500,
60+
PAUSE_EAGER_PAGE_INIT: 500,
6061
};
6162

6263
/**
@@ -625,7 +626,7 @@ class BaseViewer {
625626
// Fetch all the pages since the viewport is needed before printing
626627
// starts to create the correct size canvas. Wait until one page is
627628
// rendered so we don't tie up too many resources early on.
628-
this._onePageRenderedOrForceFetch().then(() => {
629+
this._onePageRenderedOrForceFetch().then(async () => {
629630
if (this.findController) {
630631
this.findController.setDocument(pdfDocument); // Enable searching.
631632
}
@@ -650,7 +651,7 @@ class BaseViewer {
650651
return;
651652
}
652653
for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
653-
pdfDocument.getPage(pageNum).then(
654+
const promise = pdfDocument.getPage(pageNum).then(
654655
pdfPage => {
655656
const pageView = this._pages[pageNum - 1];
656657
if (!pageView.pdfPage) {
@@ -671,6 +672,10 @@ class BaseViewer {
671672
}
672673
}
673674
);
675+
676+
if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
677+
await promise;
678+
}
674679
}
675680
});
676681

0 commit comments

Comments
 (0)