mozilla/pdf.js — pull request #4772 by Snuffleupagus (2014-05-10 10:34:44+00:00)
Title: Reduce the number of calls to PDFView.getVisiblePages from updateViewarea

Currently for every call to `updateViewarea` we call `PDFView.getVisiblePages` (at [viewer.js#L1922](https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L1922)) before calling `PDFView.renderHighestPriority` (at [viewer.js#L1928](https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L1928)); in that function we again call `getVisiblePages` (at [viewer.js#L1215](https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L1215)).

This means that every time the user scrolls, we will essentially do two back-to-back calls to `getVisiblePages`. Given that this requires traversing the DOM to check which pages are actually visible on screen, this seem like the kind of thing you really want to avoid doing if possible (especially in long documents).

To avoid the above, I've refactored `renderHighestPriority` to always return the result of `getVisiblePages`.