pdf.js/src
Jonas Jenwald 9f02cc36d4 Attempt to further reduce re-parsing for globally cached images (PR 11912, 16108 follow-up)
In PR 11912 we started caching images that occur on multiple pages globally, which improved performance a lot in many PDF documents.
However, one slightly annoying limitation of the implementation is the need to re-parse the image once the global-caching threshold has been reached. Previously this was difficult to avoid, since large image-resources will cause cleanup to run on the main-thread after rendering has finished. In PR 16108 we started delaying this cleanup a little bit, to improve performance if a user e.g. zooms and/or rotates the document immediately after rendering completes.

Taking those two PRs together, we now have a situation where it's much more likely that the main-thread has "globally used" images cached at the page-level. Hence we can instead attempt to *copy* a locally cached image into the global object-cache on the main-thread and thus reduce unnecessary re-parsing of large/complex global images, which significantly reduces the rendering time in many cases.

For the PDF document in issue 11878, the rendering time of *the second page* changes as follows (on my computer):
 - With the `master`-branch it takes >600 ms to render.
 - With this patch that goes down to ~50 ms, which is one order of magnitude faster.

(Note that all other pages are, as expected, completely unaffected by these changes.)

This new main-thread copying is limited to "large" global images, since:
 - Re-parsing of small images, on the worker-thread, is usually fast enough to not be an issue.
 - With the delayed cleanup after rendering, it's still not guaranteed that an image is available in a page-level cache on the main-thread.
 - This forces the worker-thread to wait for the main-thread, which is a pattern that you always want to avoid unless absolutely necessary.
2023-12-21 21:26:21 +01:00
..
core Attempt to further reduce re-parsing for globally cached images (PR 11912, 16108 follow-up) 2023-12-21 21:26:21 +01:00
display Attempt to further reduce re-parsing for globally cached images (PR 11912, 16108 follow-up) 2023-12-21 21:26:21 +01:00
images Vectorize the logo. 2012-10-29 14:08:52 -04:00
scripting_api Set text field value as a string when it's for a date or a time (bug 1868503) 2023-12-06 09:44:30 +01:00
shared [Editor] Add a color picker with predefined colors for highlighting text (bug 1866434) 2023-12-05 23:27:22 +01:00
interfaces.js Use ESLint to ensure that exports are sorted alphabetically 2021-01-09 20:37:51 +01:00
license_header_libre.js Update the year in the license_header files 2023-01-18 22:28:18 +01:00
license_header.js Update the year in the license_header files 2023-01-18 22:28:18 +01:00
pdf.image_decoders.js Limit the amount of console "spam" during fuzz tests (PR 17337 follow-up) 2023-12-04 16:39:45 +01:00
pdf.js [Editor] Add a color picker with predefined colors for highlighting text (bug 1866434) 2023-12-05 23:27:22 +01:00
pdf.sandbox.external.js ESMify some modules for m-c (bug 1824610) 2023-03-27 12:01:31 +02:00
pdf.sandbox.js Introduce more optional chaining in the code-base 2023-08-26 10:52:23 +02: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