> For the complete documentation index, see [llms.txt](https://hinkal-team.gitbook.io/hinkal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hinkal-team.gitbook.io/hinkal/hinkal-mobile-sdk/android/advanced/performance.md).

# Performance

Guidance for keeping the SDK responsive in a mobile app.

### Off the main thread

SDK operations do network and proof work. Call them from a coroutine on a background dispatcher and update the UI on the main thread:

```kotlin
viewModelScope.launch(Dispatchers.IO) {
    val txHash = hinkal.deposit(chainId, tokens, amounts, true, false)
    withContext(Dispatchers.Main) { updateUi(txHash) }
}
```

### Cache balances

`getTotalBalance` scans UTXOs. Cache the result and only re-scan when needed:

* Read with `resetCache = false` for normal UI reads.
* Pass `resetCache = true` after a deposit, withdrawal, transfer, or swap.

### Reuse the client and session

A session lasts across many operations. Create the `Client` once, connect once, and reuse the `Hinkal` handle - avoid reconnecting per operation.

### Batch where possible

Because tokens and amounts are JSON arrays, deposit multiple tokens in a single call rather than issuing separate deposits.
