# Optimizations

The SDK is optimized to avoid waste of resources and improve performance. You can freely choose which optimizations should be enabled or disabled.

## Multiple Calls to API

The SDK prevents the user from making multiple calls to the backend. If a call is already running, the SDK merges a new request into the current one and the data is propagated to both request origins of the `Call`.

You can change the default behavior and force calls to always make new requests to API and never merge two requests into one by using:

<tabs>

<tabs-item value="kotlin" label="Kotlin">

```kotlin
ChatClient.Builder(apiKey, context).disableDistinctApiCalls().build()
```

</tabs-item>

<tabs-item value="java" label="Java">

```java
new ChatClient.Builder(apiKey, context).disableDistinctApiCalls().build();
```

</tabs-item>

</tabs>

If you want to control new requests to API in a more granular way, you can use the extension function:

```kotlin
import io.getstream.result.call.forceNewRequest

Call<T>.forceNewRequest(): Call<T>
```

For example, you can use the snippet presented below for query channels request:

<tabs>

<tabs-item value="kotlin" label="Kotlin">

```kotlin
ChatClient.instance().queryChannels(queryChannelsRequest).forceNewRequest().enqueue { result ->
    when (result) {
        is Result.Success -> {
            // Handle success
        }
        is Result.Failure -> {
            // Handle error
        }
    }
}
```

</tabs-item>

<tabs-item value="java" label="Java">

```java
Call<List<Channel>> queryChannelsCall = ChatClient.instance().queryChannels(queryChannelsRequest);
CallExtensions.forceNewRequest(queryChannelsCall);
queryChannelsCall.enqueue(result -> {
    if (result.isSuccess()) {
        // Handle success
    } else {
        // Handle error
    }
});
```

</tabs-item>

</tabs>

The returned `Call` will be forced to make a new request to API.

## QuerySorter

To sort your objects and present them in a desired order, you can choose between two implementations of QuerySorter: `QuerySortByReflection` and `QuerySortByField`.

<admonition type="note">

`QuerySortByField` is the default implementation used by the SDK.

</admonition>

`QuerySortByReflection` uses reflection to find the fields used for comparison. This helps you avoid creating an extra comparator implementation to support your use case.

The drawback is that reflection is an expensive operation and this implementation will have lower performance compared to `QuerySortByField`.

You can choose to avoid reflection and gain performance by using `QuerySortByField` instead, but this requires some extra work. Your custom class needs to implement the `ComparableFieldProvider` interface and provide the names of the fields used to sort the list, as shown below:

```kotlin
public data class Channel(
    var id: String = "",
    var type: String = "",
    var name: String = "",
    var image: String = "",
    [...]
    var hiddenMessagesBefore: Date? = null,
    val cooldown: Int = 0,
    var pinnedMessages: List<Message> = mutableListOf(),
    var ownCapabilities: Set<String> = setOf(),
    var membership: Member? = null,
    override var extraData: MutableMap<String, Any> = mutableMapOf(),
) : CustomObject, ComparableFieldProvider {

    @Suppress("ComplexMethod")
    override fun getComparableField(fieldName: String): Comparable<*>? {
        return when (fieldName) {
            "cid" -> cid
            "id" -> id
            "type" -> type
            "name" -> name
            "image" -> image
            [...]
            "cooldown" -> cooldown
            "lastUpdated" -> lastUpdated
            else -> extraData[fieldName] as? Comparable<*>
        }
    }
}
```

<admonition type="note">

Models included in the SDK already implement the `ComparableFieldProvider` interface and include all the fields together with `extraData`.

</admonition>


---

This page was last updated at 2026-04-17T17:33:31.300Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/sdk/android/v6/client/guides/optimizations/](https://getstream.io/chat/docs/sdk/android/v6/client/guides/optimizations/).