Skip to main content

Detecting a dependency performance issue

In this tutorial, we’ll guide you through identifying a slow component within your app that may be slowing down the overall performance using the Kotzilla Platform.

info

Issue context

A dependency performance issue occurs when a component takes too long to resolve due to its complexity and the number of dependencies it retrieves. This can lead to performance bottlenecks, affecting app responsiveness and slowing down critical operations.

Why it matters?

  • Cascading impact: When a dependency has too many sub-dependencies or takes longer than 5 ms per call, it can delay multiple components relying on it.
  • Complex dependency graph: If too many dependencies are involved, the resolution process can slow down the main thread or background operations
  • Difficult to debug: These issues are not always caused by a single slow dependency but rather by the overall complexity of the dependency graph, making them harder to detect without proper analysis tools.

Suggested user resolution actions

  • Monitor dependency resolution time: Use the Kotzilla Platform to identify any component resolution times exceeding 5 ms per call and analyze their complexity.
  • Reduce complexity: Ddetect components with too many dependencies and consider refactoring them into smaller, more focused services.
  • Optimize dependency scope: Use Koin’s single vs. factory scopes effectively to avoid unnecessary re-creation of instances.
  • Apply best practices: Follow MVVM or Clean Architecture to structure dependencies efficiently, decouple large components into modular and reusable services, and cache expensive computations to avoid repeated slow resolutions.
  • Break down large dependency chains: If a component relies on too many dependencies, consider splitting them into smaller, more manageable parts.

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 slow dependency resolution

We will simulate a delay in the constructor of the OfflineFirstUserDataRepository, which is a key dependency within the app. This delay will help us observe the impact of slow resolutions on the app’s performance.

Here’s the code to introduce a 1-second delay in the OfflineFirstUserDataRepository:

internal class OfflineFirstUserDataRepository(
private val niaPreferencesDataSource: NiaPreferencesDataSource,
private val analyticsHelper: AnalyticsHelper,
) : UserDataRepository {
init {
Thread.sleep(1000)
}

override val userData: Flow<UserData> =
niaPreferencesDataSource.userData
...
}

Step 2 - Create user sessions to capture execution data

Once the delay is introduced in the component, create user sessions to capture data about how the slow initialization impacts the app. Repeat this process three times to gather consistent performance data.

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 delay in place, we will use the Koin IDE Plugin to visualise dependency resolution issues detected by the platform and affecting the performance. Open the Issues Panel in the Koin IDE Plugin and navigate to the Application Issues section.

You should see different issues including

  • Dependency performance impacting MainActivityViewModel
  • MainActivityViewModel resolution blocking the main Thread

3.2 Investigating the root cause of issues

To investigate the details of this issue click on the MainActivityViewModel has Slow Resolution Performance 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 MainActivityViewModel resolution causing a cascading slowdown that negatively affects overall app responsiveness and user experience.

3.3 User session analysis to trace the slow resolution performance

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 MainActivityViewModel is blocking the main thread for over 1000ms.
  • Most of the time is spent within the UserDataRepository. While we don’t see the OfflineFirstUserDataRepository directly in the event sequence, it’s clear that the delay is being inherited through the UserDataRepository interface.

In the Timeline View, you can clearly see how the 1-second delay during the screen lifecycle transitions, especially between the started and resumed states, causes the main thread to be blocked. The delayed initialization of OfflineFirstUserDataRepository impacts app performance.

Key takeaways

By simulating a slow resolution in OfflineFirstUserDataRepository, we explored how one slow dependency can create a global performance bottleneck in the app. The tutorial demonstrated how to identify slow components using Kotzilla Platform, analyze the impact of those components on app startup, and optimize dependency management to improve overall performance.