Skip to content

Commit

Permalink
Don't launch job for compose
Browse files Browse the repository at this point in the history
before
AsyncImagePainter.onRememberedAverage_µs       min     77.3,   median    101.5,   max    116.7
AsyncImagePainter.onRememberedCount            min    130.0,   median    130.0,   max    146.0
AsyncImagePainter.onRemembered_µs              min 10,048.4,   median 13,880.2,   max 16,900.0
timeToInitialDisplayMs                         min    256.8,   median    281.7,   max    358.9
frameDurationCpuMs                             P50       5.1,   P90       9.2,   P95      13.3,   P99     117.0

after
AsyncImagePainter.onRememberedAverage_µs       min     68.9,   median     78.7,   max     91.1
AsyncImagePainter.onRememberedCount            min    128.0,   median    141.0,   max    146.0
AsyncImagePainter.onRemembered_µs              min  8,956.1,   median 11,163.1,   max 13,111.9
timeToInitialDisplayMs                         min    234.1,   median    276.5,   max    325.7
frameDurationCpuMs                             P50       4.5,   P90       8.9,   P95      15.5,   P99     120.3
  • Loading branch information
mlykotom committed Apr 24, 2024
1 parent b7cf111 commit c8a8b45
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions coil-base/src/main/java/coil/RealImageLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,24 @@ internal class RealImageLoader(
}

override suspend fun execute(request: ImageRequest) = coroutineScope {
// Start executing the request on the main thread.
val job = async(Dispatchers.Main.immediate) {
executeMain(request, REQUEST_TYPE_EXECUTE)
}
// We don't use the async call that returns the job for Compose to micro-optimize the performance.
// The job is only needed in case of the Views implementation.

// Update the current request attached to the view and await the result.
if (request.target is ViewTarget<*>) {
// Start executing the request on the main thread.
val job = async(Dispatchers.Main.immediate) {
executeMain(request, REQUEST_TYPE_EXECUTE)
}
// Update the current request attached to the view and await the result.
request.target.view.requestManager.getDisposable(job)
}

job.await()
job.await()
} else {
// Start executing the request on the main thread.
withContext(Dispatchers.Main.immediate) {
executeMain(request, REQUEST_TYPE_EXECUTE)
}
}
}

@MainThread
Expand Down

0 comments on commit c8a8b45

Please sign in to comment.