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

Avoid reading the "disablePreferences"/"locale" options, when initializing the viewer, in extension builds #11825

Conversation

Snuffleupagus
Copy link
Collaborator

These two AppOptions are only defined in GENERIC builds, hence it's completely unnecessary to check them in the extension builds (e.g. MOZCENTRAL and CHROME).

Also, simply let the "printResolution" option be defined in all builds since it's being accessed in web/firefox_print_service.js as well.

…izing the viewer, in extension builds

These two `AppOptions` are only defined in GENERIC builds, hence it's completely unnecessary to check them in the extension builds (e.g. MOZCENTRAL and CHROME).

Also, simply let the "printResolution" option be defined in all builds since it's being accessed in `web/firefox_print_service.js` as well.
@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.67.70.0:8877/3a46f5548637a2a/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/3a46f5548637a2a/output.txt

Total script time: 2.56 mins

Published

@@ -229,7 +229,11 @@ const PDFViewerApplication = {
* @private
*/
async _readPreferences() {
if (AppOptions.get("disablePreferences") === true) {
if (
(typeof PDFJSDev === "undefined" ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what the background is for this change. Did you measure slowdowns here in the viewer? The app options are a simple/cheap lookup, so I'm having trouble figuring out if avoiding this check is beneficial given that the added code, in my opinion, doesn't improve readability... There might be a good reason for it, I'm just not seeing it right now, so perhaps you can shed some light on that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what the background is for this change.

Because to me it seems ridiculous to read something that we know will be undefined in e.g. MOZCENTRAL builds.

The app options are a simple/cheap lookup,

Yes, they should be cheap enough that that wasn't really the main motivation.

[...] if avoiding this check is beneficial given that the added code,

To me these added preprocessor checks actually helps reading/reasoning about the code, since it's no longer necessary to look at web/app_options.js to know that this particular option should only be defined in GENERIC builds.

[...] doesn't improve readability...

Well, similar pre-processor statements exists all over the code-base in both the web/ and src/ folders; I'm really not finding these particular cases any worse (or less readable) than lots of other code :-)
One example, from the viewer, is where the "locale" hash parameter is handle:

pdf.js/web/app.js

Lines 313 to 320 in a13db5d

// It is not possible to change locale for the (various) extension builds.
if (
(typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
"locale" in hashParams
) {
AppOptions.set("locale", hashParams.locale);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me these added preprocessor checks actually helps reading/reasoning about the code, since it's no longer necessary to look at web/app_options.js to know that this particular option should only be defined in GENERIC builds.

Hm, that is a fair point indeed.

@timvandermeij timvandermeij merged commit 571f287 into mozilla:master Apr 21, 2020
@timvandermeij
Copy link
Contributor

Thanks!

@Snuffleupagus Snuffleupagus deleted the extensions-viewer-less-AppOptions-lookup branch April 21, 2020 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants