-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fixes #23492: Perf regression of calling isFirefoxDefault from main thread #23556
Fixes #23492: Perf regression of calling isFirefoxDefault from main thread #23556
Conversation
val config = FxNimbus.features.defaultBrowserMessage.value() | ||
return if ( | ||
config.messageLocation == MessageSurfaceId.APP_MENU_ITEM && | ||
!browsers.isFirefoxDefaultBrowser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how BrowsersCache.all()
could impact performace, but maybe we could make it a bit faster if we inline the BrowsersCache.all(context)
call with the condition check, this way we will only call BrowsersCache.all( )
when it's the right message? . What do you think?
config.messageLocation == MessageSurfaceId.APP_MENU_ITEM &&
!BrowsersCache.all(context).isFirefoxDefaultBrowser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Decision Task broke, restarting |
I measured the performance difference. Results from original bisection:
Results from this PR:
It seems something may have changed after the initial regression causing the overall regression to be 63ms rather than ~100ms. One notable visual difference is that in the regressing builds there is a new UI element, "Set as default browser". The home screen races various UI elements against each other (when it should inflate from the top) so that may contribute to the different results. This PR improves the regression by another 34ms so we've still regressed ~29ms from the original state. Ideally we can try to address that (e.g. if we regress 30ms 2 more times, we're back to where we started) but I didn't see anything obviously actionable in the profiles. I'd be curious to see what our Nightly results say about this PR rather than my local measurements. |
5832ed9
to
014f6bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added more aggressive caching of calling into Rust and checking the browser default.
The FML builds on top of the getVariables() -> Variables
API and generates straightline kotlin to access those Variables
.
The rest of the PR #23400 converts existing Fenix code to use the generated code, so this Pr concentrates on that.
@mcomella please could you re-profile? (are there profiles on CI for PRs with the Performance label?)
nimbusValidation.settingsIcon, | ||
"drawable", | ||
context.packageName | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling getIdentifier
is entirely avoidable, for the sake of a validation.
} else { | ||
false | ||
} | ||
} ?: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines do several things:
- we put all the checking logic into one place.
- we now only call into Rust once for the default browser feature.
- we now only check
isFirefoxDefaultBrowser
after we check the surface id. There are no experiments about this currently, so this never happens now.
@jhugman this looks similar to what @mcomella described on #23556 (comment) see #23618 (comment) |
I think what is causing the regression is what @mcomella was describing above the "Set as default browser" card is showing all the time. Investigating #23618 I found that |
I tried to check out and run this PR but it crashes on start up with:
@jhugman btw, did you mean a benchmark or a profile?
Unfortunately, no – we haven't had the resources to implement something like that (e.g. our daily graphs from nightly are actually manually run with a script on a device on my desk). For benchmarks, you can run it locally if you have a low-end phone (or a high-end phone you can reproduce the regression on). See https://wiki.mozilla.org/Performance/Fenix/Performance_reviews#Benchmark_locally. This regression was to the |
5428f35
to
d96e51b
Compare
Ah. Ok yes, I keep forgetting to say: The default browser message was shown as part of the #23400 , and this PR fixes that. I've added
to comment 0. Fixed this early startup crash, with the suggested fix.
|
d96e51b
to
4a22af0
Compare
I'm not sure, whichever you needed to find that 102ms regression. Also question from the curious: given the precision of |
Sure. Results from original bisection:
Results from this PR, taken with our
These results are similar to when I last measured this PR.
I don't know statistics well so I'm not sure how well I can answer this question 😓 (and yes, our results could probably be improved by someone more familiar with statistics). Through trial-and-error we decided to execute 25 iterations of each test and to take the median values of the results to find the duration of a benchmark for a build. When we originally set these values, this had a maximum variation of ~20ms for an A/A test. In the worst case, I think this would let us catch regressions of ~40ms+ (based on this thinking I did). However, the average variation is usually smaller and we can look at the results across multiple days (so hundreds of iterations instead of 25) so in practice we've caught smaller regressions. The variation seems larger these days though: maybe ~30ms. Our nightly benchmark results dashboards (populated once a week on mondays) is here if you're curious. For context, we use local machines right now rather than CI due to limited resourcing: CI would be ideal because it's more accessible but it takes more time to implement and debug when issues occur. |
…lt from main thread (mozilla-mobile#23556) * Fixes mozilla-mobile#23492 — Fixup perf regression of calling isFirefoxDefault from the main thread * Tightening of near defunct default browser message * Fixup early crash in debug build * ktlint
Fixes #23492
Fixes #23618
Perf regression calling slow isFirefoxDefault from the main thread.
Prior #23400, the default browser message was only displayed when part of an experiment. The check that isFirefoxDefault was only done as a final check before the message is displayed.
#23400 changed the order of this, so the slow check was done each time the toolbar was created.
Fixes #23492; this PR does three things:
Now, the default browser message is displayable when an experiment toggles it on.
The isFirefoxDefault is done when the message is toggled on, but:
Pull Request checklist
To download an APK when reviewing a PR: