Closed Bug 1171157 Opened 9 years ago Closed 9 years ago

Use nested conditionals in GeckoPreferences

Categories

(Firefox for Android Graveyard :: Settings and Preferences, defect)

All
Android
defect
Not set
normal

Tracking

(firefox42 fixed)

RESOLVED FIXED
Firefox 42
Tracking Status
firefox42 --- fixed

People

(Reporter: rnewman, Assigned: sergej, Mentored)

Details

(Whiteboard: [good next bug][lang=java])

Attachments

(1 file, 2 obsolete files)

GeckoPreferences has a big `if` statement like this:

                } else if (!AppConstants.NIGHTLY_BUILD &&
                           PREFS_LOGIN_MANAGE.equals(key)) {
                    preferences.removePreference(pref);
                    i--;
                } else if (AppConstants.RELEASE_BUILD &&
                           PREFS_DISPLAY_REFLOW_ON_ZOOM.equals(key)) {
                    // Remove UI for reflow on release builds.
                    preferences.removePreference(pref);
                    i--;
                    continue;
                }

This has the potential to do excessive work: we check a flag *before* we check the pref string. If, say, the incoming pref is PREFS_UPDATER_AUTODOWNLOAD, but the updater is off, we'll never check the pref... and then we'll check every other clause until we run out of `if` statements!

We just added one that's more expensive:

                } else if (PREFS_VOICE_SEARCH_ENABLED.equals(key) &&
                        (!AppConstants.NIGHTLY_BUILD || !VoiceRecognizerUtils.supportsVoiceRecognizer(getApplicationContext(), getResources()))) {
                    // Remove UI for voice search on non nightly builds.
                    preferences.removePreference(pref);
                    i--;
                    continue;
                }

We run through this huge set of conditionals once per pref.

We should consider nesting these so that we detect the pref first and short-circuit, rather than running through the entire conditional for each non-removed pref.
This would benefit from profiling when launching settings on a mid-range device. If we're spending non-trivial time in setupPreferences, we should go ahead with this bug.
Mentor: rnewman
Whiteboard: [good next bug][lang=java]
Attached patch Light optimizations (obsolete) — Splinter Review
Attachment #8625990 - Flags: review?(rnewman)
Comment on attachment 8625990 [details] [diff] [review]
Light optimizations

Review of attachment 8625990 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM! r+ with those duplicate parens fixed.

::: mobile/android/base/preferences/GeckoPreferences.java
@@ +718,1 @@
>                              PREFS_TRACKING_PROTECTION_LEARN_MORE.equals(key))) {

Duplicate parens.

@@ +732,1 @@
>                              PREFS_HEALTHREPORT_LINK.equals(key))) {

Duplicate parens.

@@ +745,1 @@
>                              PREFS_GEO_LEARN_MORE.equals(key))) {

Duplicate parens.
Attachment #8625990 - Flags: review?(rnewman) → review+
Attached patch parens fixed (obsolete) — Splinter Review
Fixed those parens, plus one missed if statement
Attachment #8627657 - Flags: review?(rnewman)
Assignee: nobody → sergej
Status: NEW → ASSIGNED
Sergej, this doesn't apply to current trunk. Could you rebase, please?
Flags: needinfo?(sergej)
Here you go, sorry for prev version.
Flags: needinfo?(sergej)
Attachment #8628047 - Flags: review?(rnewman)
Attachment #8628047 - Flags: review?(rnewman) → review+
Attachment #8627657 - Attachment is obsolete: true
Attachment #8627657 - Flags: review?(rnewman)
Attachment #8625990 - Attachment is obsolete: true
https://hg.mozilla.org/mozilla-central/rev/658dca224bfc
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 42
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: