mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Improve global image caching for small images (PR 11912 follow-up, issue 12098)
When implementing the `GlobalImageCache` functionality I was mostly worried about the effect of *very large* images, hence the maximum number of cached images were purposely kept quite low[1].
However, there's one fairly obvious problem with that approach: In documents with hundreds, or even thousands, of *small* images the `GlobalImageCache` as implemented becomes essentially pointless.
Hence this patch, where the `GlobalImageCache`-implementation is changed in the following ways:
- We're still guaranteed to be able to cache a *minimum* number of images, set to `10` (similar as before).
- If the *total* size of all the cached image data is below a threshold[2], we're allowed to cache additional images.
This patch thus *improve*, but doesn't completely fix, issue 12098. Note that that document is created by a *very poor* PDF generator, since every single page contains the *entire* document (with all of its /Resources) and to create the individual pages clipping is used.[3]
---
[1] Currently set to `10` images; imagine what would happen to overall memory usage if we encountered e.g. 50 images each 10 MB in size.
[2] This value was chosen, somewhat randomly, to be `40` megabytes; basically five times the [maximum individual image size per page](6249ef517d/src/display/api.js (L2483-L2484)
).
[3] This surely has to be some kind of record w.r.t. how badly PDF generators can mess things up...
This commit is contained in:
parent
a3f6882b06
commit
1ab6d2c604
2 changed files with 46 additions and 11 deletions
|
@ -609,6 +609,9 @@ class PartialEvaluator {
|
|||
.then(imageObj => {
|
||||
imgData = imageObj.createImageData(/* forceRGBA = */ false);
|
||||
|
||||
if (cacheKey && imageRef && cacheGlobally) {
|
||||
this.globalImageCache.addByteSize(imageRef, imgData.data.length);
|
||||
}
|
||||
return this._sendImgData(objId, imgData, cacheGlobally);
|
||||
})
|
||||
.catch(reason => {
|
||||
|
@ -633,6 +636,7 @@ class PartialEvaluator {
|
|||
objId,
|
||||
fn: OPS.paintImageXObject,
|
||||
args,
|
||||
byteSize: 0, // Temporary entry, note `addByteSize` above.
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue