fune/toolkit/components/pdfjs/content
Jonas Jenwald 7c50ea0cdb Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer. r=pdfjs-reviewers,calixte,bdahl
Currently there's a fair bit of unneeded overhead when localizing the PDF Viewer, since *every single* string requires a round-trip from the `viewer.js` file to the `PdfStreamConverter.jsm` file.
This despite the fact that the relevant `viewer.properties` file is read *only once*, and its result is then cached, see https://searchfox.org/mozilla-central/rev/8f42809e51cb07aa4f5739932a06d14581e9dd4a/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#470-473

Hence we can improve things here by instead sending the *entire* localization data at once when it's first requested, and also cache it in the viewer, to reduce completely unneeded message passing overhead caused by localizing the PDF Viewer.

To put these changes into perspective, let's look at what happens when loading the PDF Specification; i.e. https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf
When loading that document we first of all need to localize the viewer UI, however the initialization/rendering of the PDF Document itself also causes some l10n-string lookups. All-in-all, simply loading the above PDF document in Firefox currently results in just over `3900` l10n-strings being fetched (with most of them being duplicates).
Furthermore, all these l10n-string lookups also have a measurable performance impact on the viewer UI localization. Using some, admittedly crude, benchmarking with `console.time/timeEnd` around the viewer UI localization code in https://searchfox.org/mozilla-central/rev/8f42809e51cb07aa4f5739932a06d14581e9dd4a/toolkit/components/pdfjs/content/web/viewer.js#484-485 gives the following results (using the best observed values, with `privacy.reduceTimerPrecision = false` set):

 - With the current code, the viewer UI localization takes around `12-13` ms.

 - With this patch, the viewer UI localization takes around `4-5` ms.

While these improvements are obviously not huge, they thus cannot hurt as far as I'm concerned.

(Assuming this is accepted, I'll obviously follow-up with the relevant `web/viewer.js` patch at GitHub. However, these changes must be synchronized in the both the viewer/integration code.)

Differential Revision: https://phabricator.services.mozilla.com/D139928
2022-03-11 01:24:05 +00:00
..
build Bug 1757825 - Update pdf.js to version 2.14.13 r=pdfjs-reviewers,marco 2022-03-02 22:41:56 +00:00
web Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer. r=pdfjs-reviewers,calixte,bdahl 2022-03-11 01:24:05 +00:00
PdfJs.jsm
PdfjsChild.jsm
PdfJsDefaultPreferences.jsm
PdfJsNetwork.jsm
PdfjsParent.jsm Bug 1753509 - Add support for search with or without diacritics in the pdf viewer r=pdfjs-reviewers,bdahl 2022-02-11 16:28:19 +00:00
PdfJsTelemetry.jsm Bug 1736864, add extra telemetry flag to indicate if the pdf viewer is opening an attachment, r=Gijs 2021-11-10 18:52:24 +00:00
PdfSandbox.jsm
PdfStreamConverter.jsm Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer. r=pdfjs-reviewers,calixte,bdahl 2022-03-11 01:24:05 +00:00