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

Ensure that blob: URLs will be revoked when pages are cleaned-up/destroyed (JPEG memory usage) #10644

Merged
merged 2 commits into from
Mar 16, 2019

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Mar 14, 2019

  • Ensure that blob: URLs will be revoked when pages are cleaned-up/destroyed

    Natively supported JPEG images are sent as-is, using a blob: or possibly a data URL, to the main-thread for loading/decoding.
    However there's currently no attempt at releasing these resources, which are held alive by blob: URLs, which seems unfortunately given that images can be arbitrarily large.

    As mentioned in https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL the lifetime of these URLs are tied to the document, hence they are not being removed when a page is cleaned-up/destroyed (e.g. when being removed from the PDFPageViewBuffer in the viewer).
    This is easy to test with the help of about:memory (in Firefox), which clearly shows the number of blob: URLs becomming arbitrarily large without this patch. With this patch however the blob: URLs are immediately release upon clean-up as expected, and the memory consumption should thus be considerably reduced for long documents with (simple) JPEG images.

  • Remove the src attribute from Image objects used with natively supported JPEG images, when pages are cleaned-up/destroyed

    This will further help reduce the amount of image data that's currently being held alive, by explicitly removing the src attribute.

    Please note that this is mostly relevant for browsers which do not support URL.createObjectURL, or where disableCreateObjectURL was manually set by the user, since blob: URLs will be revoked (see the previous patch).
    However, using about:memory (in Firefox) it does seem that this may also be generally helpful, given that calling URL.revokeObjectURL won't invalidate the image data itself (as far as I can tell).

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.67.70.0:8877/0904f53f3e7d886/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://54.215.176.217:8877/5c788be6d454ff8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/0904f53f3e7d886/output.txt

Total script time: 18.47 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/0904f53f3e7d886/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/5c788be6d454ff8/output.txt

Total script time: 28.99 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.215.176.217:8877/5c788be6d454ff8/reftest-analyzer.html#web=eq.log

@Snuffleupagus Snuffleupagus changed the title Ensure that blob: URLs will be revoked when pages are cleaned-up/destroyed [WIP] Ensure that blob: URLs will be revoked when pages are cleaned-up/destroyed Mar 14, 2019
@Snuffleupagus Snuffleupagus force-pushed the revokeObjectURL branch 3 times, most recently from 57c99ad to f260539 Compare March 14, 2019 19:13
…stroyed

Natively supported JPEG images are sent as-is, using a `blob:` or possibly a `data` URL, to the main-thread for loading/decoding.
However there's currently no attempt at releasing these resources, which are held alive by `blob:` URLs, which seems unfortunately given that images can be arbitrarily large.

As mentioned in https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL the lifetime of these URLs are tied to the document, hence they are not being removed when a page is cleaned-up/destroyed (e.g. when being removed from the `PDFPageViewBuffer` in the viewer).
This is easy to test with the help of `about:memory` (in Firefox), which clearly shows the number of `blob:` URLs becomming arbitrarily large *without* this patch. With this patch however the `blob:` URLs are immediately release upon clean-up as expected, and the memory consumption should thus be considerably reduced for long documents with (simple) JPEG images.
@Snuffleupagus Snuffleupagus changed the title [WIP] Ensure that blob: URLs will be revoked when pages are cleaned-up/destroyed Ensure that blob: URLs will be revoked when pages are cleaned-up/destroyed Mar 15, 2019
@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://54.215.176.217:8877/3c3b04fb922560c/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.67.70.0:8877/8e869ac1e608bed/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/8e869ac1e608bed/output.txt

Total script time: 18.06 mins

  • Font tests: Passed
  • Unit tests: FAILED
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/8e869ac1e608bed/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/3c3b04fb922560c/output.txt

Total script time: 25.75 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.215.176.217:8877/3c3b04fb922560c/reftest-analyzer.html#web=eq.log

…pported JPEG images, when pages are cleaned-up/destroyed

This will further help reduce the amount of image data that's currently being held alive, by explicitly removing the `src` attribute.

Please note that this is mostly relevant for browsers which do not support `URL.createObjectURL`, or where `disableCreateObjectURL` was manually set by the user, since `blob:` URLs will be revoked (see the previous patch).
However, using `about:memory` (in Firefox) it does seem that this may also be generally helpful, given that calling `URL.revokeObjectURL` won't invalidate the image data itself (as far as I can tell).
@Snuffleupagus Snuffleupagus changed the title Ensure that blob: URLs will be revoked when pages are cleaned-up/destroyed Ensure that blob: URLs will be revoked when pages are cleaned-up/destroyed (JPEG memory usage) Mar 16, 2019
@timvandermeij timvandermeij merged commit 7c9f1cc into mozilla:master Mar 16, 2019
@timvandermeij
Copy link
Contributor

This is a really nice find; thanks!

@timvandermeij
Copy link
Contributor

/botio makeref

(to fix reference test failures)

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/6d7037e0915eed9/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_makeref from @timvandermeij received. Current queue size: 1

Live output at: http://54.215.176.217:8877/0e8d70af0d295aa/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/6d7037e0915eed9/output.txt

Total script time: 16.53 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/0e8d70af0d295aa/output.txt

Total script time: 23.22 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants