Keep expensive local work away from the UI thread.
1. Initialization scope
Load the model in an owner with an explicit lifecycle. Do not initialize it on every recomposition. Expose readiness separately from inference progress.
2. Execution and cancellation
Use the runtime-supported threading and cancellation behavior. Coroutine cancellation does not automatically interrupt native work unless the adapter forwards it correctly.
3. Concurrency limits
A runtime may not support concurrent sessions safely or efficiently. Serialize or bound requests and report a busy state instead of creating unbounded work.
Worked scenario
Rapid taps submit five requests. A bounded adapter cancels or queues according to product policy rather than allocating five model instances.
Apply it
Build an adapter with ready, busy and closed states. Test cancel during initialization and during inference.
Check your understanding
Your UI remains responsive and ownership of native resources is unambiguous. Explain the decision and show evidence from your implementation or design. If you cannot demonstrate it yet, revisit the relevant section before continuing.