Andrej Kovar
11/11/2025, 10:32 PMAleksei Tirman [JB]
11/12/2025, 8:06 AMAndrej Kovar
11/12/2025, 8:42 AMEventRepositoryImpl(
private val eventRemoteSource: EventRemoteSource,
...
): EventRepository {
override suspend fun getEvent(eventId: String): Event? {
val apiEvent: ApiEvent = eventRemoteSource.getEvent(eventId: String)
return mapEvent(
apiEvent = apiEvent,
struct = structRepository.getStruct().firstOrNull(),
)
}
...
}
EventRemoteSourceImpl.kt
internal class EventRemoteSourceImpl(
private val eventRestRemoteSource: EventRestRemoteSource,
...
) : EventRemoteSource {
override suspend fun getEvent(eventId: String): ApiEvent? =
eventRestRemoteSource.getByEventId(query.eventId)
.successOrElse { ApiOfferV2RestData(data = null) }
.data
?.firstOrNull()
}
}
EventRestRemoteSource.kt
internal class EventRestRemoteSource(
httpClient: HttpClient,
kmpAppConfig: KmpAppConfig,
...
) : BaseRestRemoteSource(
httpClient = httpClient,
defaultRequestHeaders = { RequestHeaders(userAgent = kmpAppConfig.userAgent) }
) {
suspend fun getByEventId(eventId: String): ApiResponseResult<ApiOfferV2RestData<List<ApiEvent>>> = execute {
val response = get(
urlString = getConfiguration<OfferApiConfiguration>()
.getEventByIdRestUrl(
eventId = eventId,
includeResultedOdds = true,
)
)
decodeApiResponse(response)
}
...
}
ApiResponseResult.kt
suspend inline fun <reified T : Any> decodeApiResponse(
response: HttpResponse,
): ApiResponseResult<T> {
return try {
val responseData = response.body<T>()
ApiResponseResult.Success(responseData)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Logger.e("decodeApiResponse", e)
val errorResponse = handleApiError(response)
ApiResponseResult.Failure(ApiFailure.ApiParsingError(errorResponse))
}
}
When we replace EventRestRemoteSource with another one which is using Retrofit, we don't see this:
• Triggering much more Garbage collections with a bunch of following logs in Logcat:
◦ Waiting for a blocking GC Alloc
◦ WaitForGcToComplete blocked Alloc on Background for 868.208ms
• Heap spike up to 500MB (visible in logcat as well after GC clears the memory)Aleksei Tirman [JB]
11/12/2025, 9:12 AMHristijan
11/12/2025, 10:46 AM