Aller au contenu

HTTP Client Lifetime (ARCH9083)

Ce contenu n’est pas encore disponible dans votre langue.

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

Flags URLSession(configuration:) created inside a function body - each call rebuilds the connection pool.

func fetch(_ url: URL) async throws -> Data {
let session = URLSession(configuration: .default)
return try await session.data(from: url).0
}
private let session = URLSession(configuration: .default)
func fetch(_ url: URL) async throws -> Data { try await session.data(from: url).0 }

Create the session once and reuse it (or use URLSession.shared).