1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00
pdf.js/src
Jonas Jenwald 9241e1be8c [api-minor] Simplify clean-up of page resources after rendering
After PR 2317, which landed in 2012, we'd immediately clean-up after rendering for pages with large image resources. This had the effect that re-rendering, e.g. after zooming, would force us to re-parse the entire page which could easily lead to bad performance.
In PR 16108, which landed in 2023, we tried to lessen the impact of that by slightly delaying clean-up however that's obviously not a perfect solution (and it increased the complexity of the relevant code).

Furthermore, the condition for this "immediate" clean-up seems a bit arbitrary to me since a page could easily contain a large number of smaller images whose total size vastly exceeds the threshold.

Hence this patch, which suggests that we remove the conditional and delayed clean-up after rendering. Compared to the situation back in 2012, a number of things have improved since:
 - We have *multiple* caches for repeated image-resources on the worker-thread[1], which helps reduce overall memory usage and improves performance.
 - We downsize huge images on the worker-thread, which means that the images we're using on the main-thread cannot be arbitrarily large.
 - The amount of available RAM on devices should be a lot higher, since more than a decade has passed.

A future improvement here, for more resource constrained environments, could be to instead clean-up when actually needed using e.g. `WeakRef`s (see issue 18148).

---
[1] More specifically:
 - `LocalImageCache`, which caches image-data by /Name and /Ref on the `PartialEvaluator.prototype.getOperatorList` level.
 - `RegionalImageCache`, which caches image-data by /Ref on the `PartialEvaluator`-instance (i.e. at the page) level.
 - `GlobalImageCache`, which caches image-data by /Ref globally at the document level.
2025-01-22 12:19:44 +01:00
..
core [api-minor] Simplify clean-up of page resources after rendering 2025-01-22 12:19:44 +01:00
display [api-minor] Simplify clean-up of page resources after rendering 2025-01-22 12:19:44 +01:00
images Vectorize the logo. 2012-10-29 14:08:52 -04:00
scripting_api Let be more tolerant with predefined phone number format 2025-01-06 15:24:19 +01:00
shared [api-minor] Simplify clean-up of page resources after rendering 2025-01-22 12:19:44 +01:00
interfaces.js Ensure that the response-origin of range requests match the full request (issue 12744) 2024-11-24 10:08:29 +01:00
license_header.js Update the year in the license_header files 2024-07-02 14:34:59 +02:00
license_header_libre.js Update the year in the license_header files 2024-07-02 14:34:59 +02:00
pdf.image_decoders.js [api-minor] Remove the image-related error message prefixes 2024-04-20 12:51:45 +02:00
pdf.js [api-major] Replace MissingPDFException and UnexpectedResponseException with one exception 2025-01-16 22:51:05 +01:00
pdf.sandbox.external.js Avoid to call a function in the js sandbox when it has been destroyed 2024-06-18 22:30:21 +02:00
pdf.sandbox.js Enable the ESLint no-console rule in parts of the code-base 2024-11-14 12:41:39 +01:00
pdf.scripting.js Output pdf.scripting.js as a JavaScript module (PR 17055 follow-up) 2023-10-07 15:27:26 +02:00
pdf.worker.js Allow, optionally, using worker-modules during local development 2023-01-31 12:09:44 +01:00