Skip to content

Discard rendered pages while the reader is in a hidden tab#229

Open
pistachionet wants to merge 1 commit into
zotero:masterfrom
pistachionet:discard-hidden-tab-pages
Open

Discard rendered pages while the reader is in a hidden tab#229
pistachionet wants to merge 1 commit into
zotero:masterfrom
pistachionet:discard-hidden-tab-pages

Conversation

@pistachionet

Copy link
Copy Markdown

Each loaded PDF view retains at least 10 fully rendered page canvases (PDFPageViewBuffer, DEFAULT_CACHE_SIZE = 10 — the buffer never shrinks below that). On a 2x HiDPI display at page-width zoom a page canvas is ~2400×3100 device pixels ≈ 30 MB RGBA, up to the maxCanvasPixels = 2^25 cap. On top of that, the annotation overlay renderer (src/pdf/page.js) keeps a full-size _snapshotCanvas copy of every rendered page canvas (captured unconditionally in _maybeRefreshSnapshot(), even for pages with no annotations), plus extracted per-page data in _pdfPages. That's roughly 600 MB per loaded PDF tab, retained indefinitely while the tab is hidden, since nothing is released on tab deselection.

This pr adds Reader.setSuspended(), which for PDF views destroys all page views to release page canvases, snapshot canvases, extracted page data, and worker-side page resources, and pauses the rendering queue so nothing re-renders while hidden. On resume, rendering is unpaused and visible pages re-render through the normal path.

Each loaded reader view otherwise retains 10+ rendered page canvases (roughly 30-60 MB each on HiDPI displays) plus a same-size snapshot copy of each, indefinitely.

Also explicitly zero snapshot canvas backing stores when a page is destroyed, instead of waiting for GC.

Requires the PDFRenderingQueue paused flag from the zotero/pdf.js companion PR.

Adds Reader.setSuspended(), which for PDF views destroys all page views
to release page canvases, snapshot canvases, extracted page data, and
worker-side page resources, and pauses the rendering queue so nothing
re-renders while hidden. On resume, rendering is unpaused and visible
pages re-render through the normal path.

Each loaded reader view otherwise retains 10+ rendered page canvases
(roughly 30-60 MB each on HiDPI displays) plus a same-size snapshot
copy of each, indefinitely.

Also explicitly zero snapshot canvas backing stores when a page is
destroyed, instead of waiting for GC.

Requires the PDFRenderingQueue paused flag from the zotero/pdf.js
companion PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant