From c0671ac13341dde2b0378771dc846cad84352a9c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 4 Mar 2023 11:22:59 +0100 Subject: [PATCH] Slightly increase the maximum image sizes that we'll cache The current value originated in PR 2317, and in the decade that have passed the amount of RAM available in (most) devices should have increased a fair bit. Nowadays we also do a much better job of detecting repeated images at both the page- and document-level, which helps reduce overall memory-usage in many documents. Finally the constant is also moved into the `src/shared/util.js` file, since it was implicitly used on both the main- and worker-thread previously. --- src/core/image_utils.js | 10 ++++++++-- src/display/api.js | 4 ++-- src/shared/util.js | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/image_utils.js b/src/core/image_utils.js index 8cef91dc0..1dfb5b740 100644 --- a/src/core/image_utils.js +++ b/src/core/image_utils.js @@ -13,7 +13,13 @@ * limitations under the License. */ -import { assert, shadow, unreachable, warn } from "../shared/util.js"; +import { + assert, + MAX_IMAGE_SIZE_TO_CACHE, + shadow, + unreachable, + warn, +} from "../shared/util.js"; import { RefSetCache } from "./primitives.js"; class BaseLocalCache { @@ -160,7 +166,7 @@ class GlobalImageCache { } static get MAX_BYTE_SIZE() { - return shadow(this, "MAX_BYTE_SIZE", /* Forty megabytes = */ 40e6); + return shadow(this, "MAX_BYTE_SIZE", 5 * MAX_IMAGE_SIZE_TO_CACHE); } constructor() { diff --git a/src/display/api.js b/src/display/api.js index e44dd78ba..00adb9044 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -26,6 +26,7 @@ import { info, InvalidPDFException, isArrayBuffer, + MAX_IMAGE_SIZE_TO_CACHE, MissingPDFException, PasswordException, RenderingIntentFlag, @@ -2811,7 +2812,6 @@ class WorkerTransport { pageProxy.objs.resolve(id, imageData); // Heuristic that will allow us not to store large data. - const MAX_IMAGE_SIZE_TO_STORE = 8000000; if (imageData) { let length; if (imageData.bitmap) { @@ -2821,7 +2821,7 @@ class WorkerTransport { length = imageData.data?.length || 0; } - if (length > MAX_IMAGE_SIZE_TO_STORE) { + if (length > MAX_IMAGE_SIZE_TO_CACHE) { pageProxy._maybeCleanupAfterRender = true; } } diff --git a/src/shared/util.js b/src/shared/util.js index d500aa9a7..873e26e0c 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -26,6 +26,8 @@ if ( const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; +const MAX_IMAGE_SIZE_TO_CACHE = 10e6; // Ten megabytes. + // Represent the percentage of the height of a single-line field over // the font size. Acrobat seems to use this value. const LINE_FACTOR = 1.35; @@ -1060,6 +1062,7 @@ export { isArrayEqual, LINE_DESCENT_FACTOR, LINE_FACTOR, + MAX_IMAGE_SIZE_TO_CACHE, MissingPDFException, objectFromMap, objectSize,