Detecting a background performance issue
In this tutorial, we’ll guide you through identifying thread blockages that cause long components loading times in your app using the Kotzilla Platform.
Issue context
Background performance issues arise when background tasks consume too many resources or take too long to execute, impacting app responsiveness and overall performance
Why it matters?
Inefficient background processing can drain device resources, slow down the app, and lead to a poor user experience.
Suggested user resolution actions
To fix thread blockages, monitor and reduce any time-consuming component or dependency resolution that take more than 100 ms on background threads.
- Profile background tasks: Use the Kotzilla Platform to analyze and optimize background operations, ensuring they run efficiently.
- Use proper threading: Implement background operations using optimized threading strategies like
WorkManager
orCoroutines
in Kotlin. - Resource management: Limit resource-intensive tasks and use efficient scheduling mechanisms to avoid excessive resource consumption.
- Efficient scoping: Use Koin’s scoping features to manage background tasks efficiently, ensuring they are only active when necessary.
Prerequisites
In this tutorial, we will be using the NowInAndroid app as an example. Before you begin, ensure you've completed the first two steps of the Get started with Kotzilla Platform
Step 1- Simulate a blockage in a background thread
We’ll simulate a background thread blockage by introducing a 1-second delay in the SyncWorker
class. This will let us observe how thread blockages impact the app’s performance, even in background tasks.
Here’s the code to introduce a 1-second delay in the SyncWorker
:
class SyncWorker(
appContext: Context,
workerParams: WorkerParameters
) : ListenableWorker(appContext, workerParams) {
override suspend fun doWork(): Result {
// Simulate a background task delay
Thread.sleep(1000)
return Result.success()
}
}
Step 2- Create user sessions to capture execution data
After adding the simulated delay, create a user session to capture the performance data. This will allow Kotzilla to record the impact of the background thread delay.
Follow the navigation steps detailed in this guide to simulate a repeatable sequence of interactions. Repeat this three times to create consistent data on Kotzilla Platform.
Step 3- Analyze results in Kotzilla Platform
3.1 Observing impact on user sessions
After completing the user sessions, log into the Kotzilla Platform and navigate to the Dashboard View of your app. Here, click on the Sessions View to see the recorded sessions. In the Max Event Duration column, you will observe the 1-second delay caused by the simulated blockage in the SyncWorker
.
In the Timeline View, the delay in the SyncWorker
can be observed. While there is no visible impact on the UI, the WM.task-1
thread is delayed by over a second, indicating the impact on background task execution:
3.2 Investigating the sequence of events
The detailed sequence of events for the ListenableWorker
in the timeline highlights the 1-second delay in the execution of background tasks. This analysis shows how even asynchronous tasks can be delayed by blocked threads:
This scenario emphasizes the importance of monitoring background threads, as even asynchronous execution can be delayed by blocking threads. The delay in the background task can lead to poor performance, especially when multiple tasks depend on each other.
Key takeaways
By simulating a 1-second delay in the SyncWorker
, we observed how thread blockages can affect both background tasks and overall app performance. Using Kotzilla Platform, we identified how blocked threads can lead to slowdowns, even when UI threads remain unaffected. Monitoring these background tasks and resolving bottlenecks in thread execution is important for improving the app’s responsiveness and performance.