mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 07:38:07 +02:00
[api-major] Only create a StatTimer
for pages when enableStats == true
(issue 5215)
Unless the debugging tools (i.e. `PDFBug`) are enabled, or the `browsertest` is running, the `PDFPageProxy.stats` aren't actually used for anything. Rather than initializing unnecessary `StatTimer` instances, we can simply re-use *one* dummy class (with static methods) for every page. Note that by using a dummy `StatTimer` in this way, rather than letting `PDFPageProxy.stats` be undefined, we don't need to guard *every* single stats collection callsite. Since it wouldn't make much sense to attempt to use `PDFPageProxy.stats` when stat collection is disabled, it was instead changed to a "private" property (i.e. `PDFPageProxy._stats`) and a getter was added for accessing `PDFPageProxy.stats`. This getter will now return `null` when stat collection is disabled, making that case easy to handle. For benchmarking purposes, the test-suite used to re-create the `StatTimer` after loading/rendering each page. However, modifying properties on various API code from the outside in this way seems very error-prone, and is an anti-pattern that we really should avoid at all cost. Hence the `PDFPageProxy.cleanup` method was modified to accept an optional parameter, which will take care of resetting `this.stats` when necessary, and `test/driver.js` was updated accordingly. Finally, a tiny bit more validation was added on the viewer side, to ensure that all the code we're attempting to access is defined when handling `PDFPageProxy` stats.
This commit is contained in:
parent
50b72dec6e
commit
7c5ba9aad5
5 changed files with 59 additions and 19 deletions
|
@ -19,8 +19,6 @@
|
|||
var WAITING_TIME = 100; // ms
|
||||
var PDF_TO_CSS_UNITS = 96.0 / 72.0;
|
||||
|
||||
var StatTimer = pdfjsDistBuildPdf.StatTimer;
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
|
@ -536,9 +534,10 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
|||
if (annotationLayerCanvas) {
|
||||
ctx.drawImage(annotationLayerCanvas, 0, 0);
|
||||
}
|
||||
page.cleanup();
|
||||
task.stats = page.stats;
|
||||
page.stats = new StatTimer();
|
||||
if (page.stats) { // Get the page stats *before* running cleanup.
|
||||
task.stats = page.stats;
|
||||
}
|
||||
page.cleanup(/* resetStats = */ true);
|
||||
self._snapshot(task, error);
|
||||
});
|
||||
initPromise.then(function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue