Closed vegaro closed 3 hours ago
Attention: Patch coverage is 97.87234%
with 1 line
in your changes missing coverage. Please review.
Project coverage is 83.31%. Comparing base (
80781e4
) to head (639329d
). Report is 3 commits behind head on main.
Files | Patch % | Lines |
---|---|---|
.../com/revenuecat/purchases/PurchasesOrchestrator.kt | 94.11% | 0 Missing and 1 partial :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Description
This PR addresses a significant number of ANRs (Application Not Responding errors) reported, such as in issue #1629.
Problem
The method
IdentityManager.configure
is currently running on the main thread and accessingSharedPreferences
. AccessingSharedPreferences
can be costly, especially if the XML file storing the preferences is large. This cost is particularly high during the initial accesses, as the XML file needs to be read and parsed, which can block the main thread and lead to ANRs.Solution
Custom Dispatcher: This PR introduces a custom dispatcher to the
IdentityManager
, allowing configure to run on a background thread. By moving this operation off the main thread, we avoid blocking it with the potentially expensive SharedPreferences access. Main Thread Optimization: The remaining setup inPurchasesOrchestrator
has been deferred to execute after configure completes, ensuring the main thread remains unblocked and improving overall app responsiveness.Notes
While this fix should mitigate the reported ANRs, it's possible there are other underlying causes contributing to these issues. This PR serves as a good initial step towards improving performance.