woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
257 stars 108 forks source link

Dynamic dashboard: Fix thread priority inversion warning #12629

Closed itsmeichigo closed 2 weeks ago

itsmeichigo commented 2 weeks ago

Closes: #12536

Description

When syncing stats on the dashboard screen, we track the performance after the syncing completes. These were called immediately inside the reloadData methods on StorePerformanceViewModel and TopPerformersDashboardViewModel. Both methods are async and marked with @MainActor for the results to be returned on the main thread.

When sending Tracks events, the events are created and saved to CoreData using performAndWait. If I understand correctly, this is to make it safe to send events continuously and synchronously. However, this happens on a background thread and blocks the async methods running on the main thread, causing potential UI hang, thus Xcode logs a warning for thread priority inversion.

To fix this issue, I created a separate publisher to keep track when syncing stats completes, and observe the data stream in a background thread before sending Tracks events. This makes sure that Tracks doesn't block the async method on the main thread.

Testing instructions

Screenshots

N/A


wpmobilebot commented 2 weeks ago

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr12629-470e292
Version18.4
Bundle IDcom.automattic.alpha.woocommerce
Commit470e292c921d0290c1fea60e5a251f2f999ddb30
App Center BuildWooCommerce - Prototype Builds #8922

Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.