Zum Inhalt springen

HTTP Client Lifetime (ARCH8083)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key kotlin.performance.http-client-lifetime · Severity error · Category performance

Flags an HTTP client (OkHttpClient, HttpClient, Retrofit) constructed inside a function body - each call pays connection pool and TLS setup again.

fun fetch(url: String) = OkHttpClient().newCall(Request.Builder().url(url).build()).execute()
private val client = OkHttpClient()
fun fetch(url: String) = client.newCall(Request.Builder().url(url).build()).execute()

Create the client once (a property, a DI singleton) and reuse it.