6da0944fc7
*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
|
||
---|---|---|
.. | ||
.eslintrc | ||
annotation_spec.js | ||
annotation_storage_spec.js | ||
api_spec.js | ||
base_viewer_spec.js | ||
bidi_spec.js | ||
cff_parser_spec.js | ||
clitests_helper.js | ||
clitests.json | ||
cmap_spec.js | ||
colorspace_spec.js | ||
core_utils_spec.js | ||
crypto_spec.js | ||
custom_spec.js | ||
default_appearance_spec.js | ||
display_svg_spec.js | ||
display_utils_spec.js | ||
document_spec.js | ||
encodings_spec.js | ||
evaluator_spec.js | ||
fetch_stream_spec.js | ||
function_spec.js | ||
jasmine-boot.js | ||
message_handler_spec.js | ||
metadata_spec.js | ||
murmurhash3_spec.js | ||
network_spec.js | ||
network_utils_spec.js | ||
node_stream_spec.js | ||
parser_spec.js | ||
pdf_find_controller_spec.js | ||
pdf_find_utils_spec.js | ||
pdf_history_spec.js | ||
primitives_spec.js | ||
scripting_spec.js | ||
stream_spec.js | ||
struct_tree_spec.js | ||
test_utils.js | ||
testreporter.js | ||
type1_parser_spec.js | ||
ui_utils_spec.js | ||
unicode_spec.js | ||
unit_test.html | ||
util_spec.js | ||
writer_spec.js | ||
xfa_formcalc_spec.js | ||
xfa_parser_spec.js | ||
xfa_serialize_data_spec.js | ||
xfa_tohtml_spec.js | ||
xml_spec.js |