-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Issue #19147: Move set startup metrics off main thread #19397
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19397 +/- ##
============================================
+ Coverage 35.08% 35.09% +0.01%
Complexity 1626 1626
============================================
Files 542 542
Lines 21861 21866 +5
Branches 3243 3243
============================================
+ Hits 7670 7674 +4
- Misses 13300 13302 +2
+ Partials 891 890 -1
Continue to review full report at Codecov.
|
As discussed offline, I'll get this merged before performance team can do another round of tests on the build. Removing @mcomella as assigned reviewer. Thanks |
setStartupMetrics(components.core.store, settings()) | ||
// We avoid blocking the main thread on startup by setting startup metrics on the background thread. | ||
val isLoggedIn = | ||
components.backgroundServices.accountManager.accountProfile() != null |
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.
Moving the account manager to this place would also early initialize it during the Application
creation which we would want to avoid.
I think using a pref to store the loggedIn
state when the account manager is done initializing might be a quick fix for this. It's something we're doing for other settings that we want to submit to the ping as well. All future reads of this pref should give you the right value.
An alternative, is if observe the account manager and submit all these metrics when everything is done. I'm not sure how Glean SDK is required to work to know if this will cause faults in our data though, we're already trying to solve this issue right now after all.
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.
Good catch, I'll look into solving this issue.
I discussed this with Roger offline since I'm also working on a similar problem with Glean in Focus as well. One suggestion that might work is if we can set all our values first, before we submit them. Something like the code below: val readAndSetMetrics = CoroutineScope(Dispatchers.IO).async {
Metrics.distributionId.set(value)
Metrics.defaultBrowser.set(otherValue)
}
MainScope().launch {
// wait for this task to be complete first.
readAndSetMetrics.await()
// send everything to Glean
activationPing.checkAndSend()
installationPing.checkAndSend()
} |
Yes, this change could re-introduce the problems that #19252 that we're trying to solve. However, we have not confirmed #19252 does fix the problem. A performance slowdown of over 8% on all user is in my opinion not acceptable for a workaround. My thought is we first try this change in the background thread and if it doesn't work we can then explore other options or wait for a completed investigation of https://bugzilla.mozilla.org/show_bug.cgi?id=1706637. I'm hoping for a good compromise between performance and telemetry. Thanks, |
That sounds like a good plan, thanks! |
Did a quick query limiting results from the last two days. There are still about 72% of values are null. However, versus last 28 days of 80% it's an improvement. Here's the query: https://sql.telemetry.mozilla.org/queries/79931 |
As discussion offline with @mcomella I'll hold of merging this change until next week. This gives us more data to confirm that the workaround does work when it's done on the main thread. |
If you filter by those client that might have the fix (based on the app build & commit date of the fix, not sure if there's a better way to match into what build a certain commit went), then only 7% still sent NULL values for I agree that an 8% slowdown is not acceptable right now. I'll prioritize the investigation on our end this week. |
setStartupMetrics(components.core.store, settings()) | ||
// We avoid blocking the main thread on startup by setting startup metrics on the background thread. | ||
val store = components.core.store | ||
GlobalScope.launch(Dispatchers.Default) { |
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.
nit: This should probably be the IO
dispatcher since we're reading prefs from disk for this change.
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.
Agreed. I'll change it to Dispatchers.IO.
We can go ahead and merge this since we've now confirmed that the original solution of moving startup metrics to after Glean initialization works. |
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 ran this patch through the profiler and confirmed with a comparison (without the changes) that we get back our gains in pref.
We can verify the Glean bits work after this has landed in that case.
Pull Request checklist
To download an APK when reviewing a PR: