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
) : CoroutineWorker(appContext, workerParams) {
init {
// Creates a 1000ms delay in the constructor to simulate a background thread blockage
Thread.sleep(1000)
}
override suspend fun doWork(): Result {
// Perform background work
return Result.success()
}
}
Step 2- Create user sessions to capture app execution data.
With the simulated delay added, create a user session that will allow the Kotzilla SDK to capture and display the issue.
Run the Now In Android app as described in this guide to simulate a repeatable sequence of interactions. Repeat this three times to create consistent data on Kotzilla Platform.
Step 3- Investigate root cause of issues
With the simulated 1000ms delay in the background thread, the Kotzilla Platform automatically detects a background performance issue, as the SyncWorker is taking longer than 100ms to resolve its tasks.
3.1 View issues in the Koin IDE Plugin
- Open the Issues Panel in the Koin IDE Plugin.
- Navigate to the Application Issues section.
- You should see a detected issue for
SyncWorker
resolution that is blocking background thread execution
3.2 Investigating the root cause of issues
To investigate the details of this issue click on the
ListenableWorker Resolution is Blocking Background Thread
issue in the Koin IDE Plugin. This will redirect you to the Issue Details view in the Kotzilla Console.
Here, you will see:
- A list of 3 impacted user sessions.
- A detailed description of the issue, including that the
ListenableWorker
resolution is running on background thread for more than 100 ms
3.3 User session analysis to trace the background thread blocage
Click on the first impacted user session to drill down into the specific events and components related to the issue. This will take you directly to the Timeline View, where you will observe:
- The SyncWorker is blocking a background thread for more than 1000ms.
- Several dependencies tied to the SyncWorker have performance issues due to delayed task resolution.
- The background thread performance is impacted by the complexity of the dependency graph, with 19 dependencies involved in the background task resolution.
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:
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. Monitoring these background tasks and resolving bottlenecks in thread execution is important for improving the app’s responsiveness and performance.