pdf.js/src/display
Jonas Jenwald 6da0944fc7 [api-minor] Replace PDFDocumentProxy.getStats with a synchronous PDFDocumentProxy.stats getter
*Please note:* These changes will primarily benefit longer documents, somewhat at the expense of e.g. one-page documents.

The existing `PDFDocumentProxy.getStats` function, which in the default viewer is called for each rendered page, requires a round-trip to the worker-thread in order to obtain the current document stats. In the default viewer, we currently make one such API-call for *every rendered* page.
This patch proposes replacing that method with a *synchronous* `PDFDocumentProxy.stats` getter instead, combined with re-factoring the worker-thread code by adding a `DocStats`-class to track Stream/Font-types and *only send* them to the main-thread *the first time* that a type is encountered.

Note that in practice most PDF documents only use a fairly limited number of Stream/Font-types, which means that in longer documents most of the `PDFDocumentProxy.getStats`-calls will return the same data.[1]
This re-factoring will obviously benefit longer document the most[2], and could actually be seen as a regression for one-page documents, since in practice there'll usually be a couple of "DocStats" messages sent during the parsing of the first page. However, if the user zooms/rotates the document (which causes re-rendering), note that even a one-page document would start to benefit from these changes.

Another benefit of having the data available/cached in the API is that unless the document stats change during parsing, repeated `PDFDocumentProxy.stats`-calls will return *the same identical* object.
This is something that we can easily take advantage of in the default viewer, by now *only* reporting "documentStats" telemetry[3] when the data actually have changed rather than once per rendered page (again beneficial in longer documents).

---
[1] Furthermore, the maximium number of `StreamType`/`FontType` are `10` respectively `12`, which means that regardless of the complexity and page count in a PDF document there'll never be more than twenty-two "DocStats" messages sent; see 41ac3f0c07/src/shared/util.js (L206-L232)

[2] One example is the `pdf.pdf` document in the test-suite, where rendering all of its 1310 pages only result in a total of seven "DocStats" messages being sent from the worker-thread.

[3] Reporting telemetry, in Firefox, includes using `JSON.stringify` on the data and then sending an event to the `PdfStreamConverter.jsm`-code.
In that code the event is handled and `JSON.parse` is used to retrieve the data, and in the "documentStats"-case we'll then iterate through the data to avoid double-reporting telemetry; see https://searchfox.org/mozilla-central/rev/8f4c180b87e52f3345ef8a3432d6e54bd1eb18dc/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#515-549
2021-11-20 12:20:55 +01:00
..
annotation_layer.js [api-minor] Render pushbuttons on their own canvas (bug 1737260) 2021-11-12 15:37:33 +01:00
annotation_storage.js Annotations - Avoid empty value in text field when storage contains something for it (bug 1719148) 2021-09-18 15:08:22 +02:00
api.js [api-minor] Replace PDFDocumentProxy.getStats with a synchronous PDFDocumentProxy.stats getter 2021-11-20 12:20:55 +01:00
base_factory.js Re-factor the DOMSVGFactory to extend an abstract base class 2021-06-11 17:15:49 +02:00
canvas.js [api-minor] Render pushbuttons on their own canvas (bug 1737260) 2021-11-12 15:37:33 +01:00
content_disposition.js Use the stringToBytes helper function in more places 2021-05-22 12:23:09 +02:00
display_utils.js [api-minor] Add a wrapper around the addLinkAttributes-function, in the API, to the PDFLinkService implementations 2021-10-02 12:28:00 +02:00
fetch_stream.js Fix handling of fetch errors 2021-08-30 12:43:28 +01:00
font_loader.js Replace the remaining Node.removeChild() instances with Element.remove() 2021-11-16 17:52:50 +01:00
metadata.js Convert Metadata to use private class fields 2021-10-22 22:01:19 +02:00
network_utils.js [api-minor] Support the Content-Disposition filename in the Firefox PDF Viewer (bug 1694556, PR 9379 follow-up) 2021-02-26 10:50:29 +01:00
network.js Implement PDFNetworkStreamRangeRequestReader._onError, to handle range request errors with XMLHttpRequest (issue 9883) 2021-08-31 10:23:57 +02:00
node_stream.js Account for formatting changes in Prettier version 2.3.0 2021-05-16 11:44:05 +02:00
node_utils.js Move most functionality in the create methods into the BaseCanvasFactory 2021-06-11 17:15:47 +02:00
optional_content_config.js Treat all content as visible when no optional content groups are defined (issue 13971) 2021-09-04 08:13:37 +02:00
pattern_helper.js Create shading patterns the size of the current path. (bug 1722807) 2021-11-05 20:44:18 -07:00
svg.js Fix pattern handling regression in SVGGraphics (PR 13770 follow-up) 2021-10-18 21:40:10 +02:00
text_layer.js Fix issues in text selection 2021-10-17 16:27:05 +02:00
transport_stream.js Clear some Arrays, rather than re-initialize them, in src/display/-code 2021-04-24 13:00:53 +02:00
worker_options.js Use typedef to define the type of GlobalWorkerOptions. 2020-08-03 19:06:28 +09:00
xfa_layer.js Support rich content in markup annotation 2021-10-31 13:44:51 +01:00
xfa_text.js XFA - Support text search in XFA documents. 2021-08-23 08:44:20 -07:00