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

[api-minor] Remove the postMessageTransfers parameter, and thus the ability to manually disable transferring of data, from the API #11123

Merged

Conversation

Snuffleupagus
Copy link
Collaborator

By transferring, rather than copying, ArrayBuffers between the main- and worker-threads, you can avoid unnecessary allocations by only having one copy of the same data.
Hence manually setting postMessageTransfers: false, when calling getDocument, is a performance footgun[1] which will do nothing but waste memory.

Given that every reasonably modern browser supports postMessage transfers[2], I really don't see why it should be possible to force-disable this functionality.
Looking at the browser support, for postMessage transfers[2], it's highly unlikely that PDF.js is even usable in browsers without it. However, the feature testing of postMessage transfers is kept for the time being just to err on the safe side.


[1] This is somewhat similar to the, now removed, disableWorker parameter which also provided API users a much too simple way of reducing performance.

[2] See e.g. https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage#Browser_compatibility and https://developer.mozilla.org/en-US/docs/Web/API/Transferable#Browser_compatibility

…setting up the `WorkerMessageHandler`

This check was added in PR 2445, however it's no longer necessary since all data[1] is now loaded on the main-thread (and then transferred to the worker-thread).
Furthermore, by default the Fetch API is now (usually) used rather than `XMLHttpRequest`.

All in all, while these checks *were* necessary at one point that's no longer the case and they can thus be removed.

---
[1] This includes both the actual PDF data, as well as the CMap data.
…eHandler.setup` method

Note how the sent values have inconsistent types, with a boolean in one case and an object in the other (normal) case.
Furthermore, explicitly sending a `supportTypedArray: true` property seems superfluous at least to me.
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Sep 5, 2019

From: Bot.io (Windows)


Received

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

Live output at: http://54.215.176.217:8877/eaf14e1511ad622/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 5, 2019

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/0441ae35294acd4/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 5, 2019

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/0441ae35294acd4/output.txt

Total script time: 17.56 mins

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

@pdfjsbot
Copy link

pdfjsbot commented Sep 5, 2019

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/eaf14e1511ad622/output.txt

Total script time: 26.01 mins

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

… ability to manually disable transferring of data, from the API

By transfering, rather than copying, `ArrayBuffer`s between the main- and worker-threads, you can avoid unnecessary allocations by only having *one* copy of the same data.
Hence manually setting `postMessageTransfers: false`, when calling `getDocument`, is a performance footgun[1] which will do nothing but waste memory.

Given that every reasonably modern browser supports `postMessage` transfers[2], I really don't see why it should be possible to force-disable this functionality.
Looking at the browser support, for `postMessage` transfers[2], it's highly unlikely that PDF.js is even usable in browsers without it. However, the feature testing of `postMessage` transfers is kept for the time being just to err on the safe side.

---
[1] This is somewhat similar to the, now removed, `disableWorker` parameter which also provided API users a much too simple way of reducing performance.

[2] See e.g. https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage#Browser_compatibility and https://developer.mozilla.org/en-US/docs/Web/API/Transferable#Browser_compatibility
@timvandermeij timvandermeij merged commit a79cb2d into mozilla:master Sep 6, 2019
@timvandermeij
Copy link
Contributor

timvandermeij commented Sep 6, 2019

Looks good! I also don't see any reason to keep this.

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