Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache pages at the start of drawing, not the end. #4932

Merged
merged 1 commit into from
Jun 13, 2014

Conversation

nnethercote
Copy link
Contributor

When we finish drawing a PageView, we add it to the PageView cache (this happens within the pageViewDrawCallback function within PageView.draw()). Once in the cache, it will be destroyed (via PageView.destroy()), once 20 more PageViews have been drawn, and its canvas memory can then be freed.

This is good, except it falls down in one case: when scrolling really quickly through a document, we start drawing each page but then usually move past it before it finishes drawing. When this happen, its drawing pauses because it's no longer the highest-priority page (this happens within renderContext.continueCallback in PageView.draw()).

At this point such a page is not in the cache, so it can't be destroyed. If you scroll quickly through a lot of pages, most of them will end up in this state. The only way such a page can be destroyed is by navigating back to it, whereupon its drawing will resume (within PDFView.renderView) and complete, and
it will be put into the cache.

(Now, it appears that the browser can free the canvas memory even if the page isn't destroyed. But in Firefox, this apparently doens't happen until the canvas memory has been unused for 10s of seconds, and it's very easy for canvas memory consumption to spike massively in that time.)

Fortunately, there's an easy way to fix this: just put each page in the cache as soon as it starts drawing, instead of when it finishes drawing.

This makes a big difference in practice. Scrolling through three large documents on my Mac, peak RSS dropped greatly:

  • tele: ~3000 MiB --> ~930 MiB
  • ML: ~5700 MiB --> ~1460 MiB
  • book: ~7600 MiB --> ~1360 MiB

@Snuffleupagus
Copy link
Collaborator

/botio-windows preview

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.22.172.223:8877/63e9de9c76872a2/output.txt

@yurydelendik
Copy link
Contributor

Thank you for the patch

yurydelendik added a commit that referenced this pull request Jun 13, 2014
Cache pages at the start of drawing, not the end.
@yurydelendik yurydelendik merged commit 97560ef into mozilla:master Jun 13, 2014
@nnethercote nnethercote deleted the cache-pages-earlier branch June 13, 2014 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants