mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 23:58: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
|
@ -1668,7 +1668,8 @@ function webViewerPageRendered(evt) {
|
|||
thumbnailView.setImage(pageView);
|
||||
}
|
||||
|
||||
if (PDFJS.pdfBug && Stats.enabled && pageView.stats) {
|
||||
if (PDFJS.pdfBug && typeof Stats !== 'undefined' && Stats.enabled &&
|
||||
pageView.stats) {
|
||||
Stats.add(pageNumber, pageView.stats);
|
||||
}
|
||||
|
||||
|
@ -1957,9 +1958,9 @@ function webViewerPageChanging(evt) {
|
|||
}
|
||||
|
||||
// we need to update stats
|
||||
if (PDFJS.pdfBug && Stats.enabled) {
|
||||
if (PDFJS.pdfBug && typeof Stats !== 'undefined' && Stats.enabled) {
|
||||
let pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
|
||||
if (pageView.stats) {
|
||||
if (pageView && pageView.stats) {
|
||||
Stats.add(page, pageView.stats);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue