Skip to main content

Detecting a child dependency performance issue

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

info

Issue context

In Koin, components often depend on other services or objects. If a child dependency (a dependency used within another component) is poorly optimized or slow, it can create a performance bottleneck, affecting the entire component hierarchy

Why it matters?

A single slow child dependency can cause:

  • Cascading performance issues: if a key dependency (i.e, a repository or data source) is slow, every feature that relies on it will experience slowdowns.
  • Blocked main thread execution: if the slow dependency is resolved on the main thread, it can cause UI delays and poor app responsiveness.
  • Difficult to isolate bottlenecks: the impact may not appear directly in logs but surfaces in the parent component that depends on the slow service.

Suggested user resolution actions

To fix child dependency performance issues, monitor and optimize any dependency resolution exceeding 5 ms per call:

  • Profile slow dependencies: Use the Kotzilla Platform to detect long resolution times in the dependency graph.
  • Reduce resolution time: Optimize child dependencies to avoid cascading delays in parent components.
  • Optimize Koin configurations: Use single instead of factory where appropriate to reduce unnecessary re-initialization.
  • Refactor dependencies: Break down complex services into smaller, focused components to simplify execution logic.

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 component 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 child resolution on the app’s performance.

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

class OfflineFirstUserDataRepository() {
init {
// Simulate a 1-second delay during initialization
Thread.sleep(1000)
}
}

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 slow resolution blocking the main Thread
  • MainActivityViewModelchild dependency has slow resolution performance

3.2 Investigating the root cause of issues

To investigate the details of this issue click on the MainActivityViewModel child dependency has a 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:

  • MainActivityViewModel blocks the main thread for over 1000ms
  • Most of the delay originates from UserDataRepository
  • OfflineFirstUserDataRepository is the root cause of the performance issue

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 a slow child dependency can degrade overall app performance by introducing cascading delays. The Kotzilla Platform helps detect these issues by tracing slow resolutions in the dependency graph. Optimizing child dependencies ensures smooth execution and better UI responsiveness.