Slow scrolling in paging3 load function

I’m encountering slow loading as I scroll because of multiple network calls that need to be made.

class RepoResultPagingSource(
private val repository: Repository,
private val query: String
) : PagingSource<Int, Result>() {

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Result> {
    try {
        val page = params.key ?: 1
        // network call to get repositories
        val repos = repository.getRepositories(query, page, PAGE_SIZE)

        val results = repos.map { repo ->
            // uses repo to get its top contributor
            val contributor = repository.getTopContributor(repo.owner.username, repo.reponame)
            Result(repo.owner.url, repo.reponame, contributor.username?: "")
        }
        return LoadResult.Page(
            data = repoResults,
            prevKey = if (page == 1) null else page-1,
            nextKey = page + 1
        )
    } catch (e: Exception) {
        return LoadResult.Error(e)
    }
}

class Repository(private val api: RepositoryApi,
             private val dispatcher: CoroutineDispatcher = Dispatchers.IO) {
    suspend fun getRepositories(query: String, page: Int, perPage: Int): List<Repository> 
    {
       return withContext(dispatcher) {
           api.search(query, page, perPage).repositories
       }
    }

    suspend fun getTopContributor(ownerName: String, repoName: String): Contributor {
        return withContext(dispatcher) {
            api.getContributors(ownerName, repoName, 1).first()
        }
    }
}

I realized that load was blocking because the paging library calls it from runBlockin

@JvmStatic
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    public fun <K : Any, T : Any> create(
        pagingSource: PagingSource<K, T>,
        initialPage: PagingSource.LoadResult.Page<K, T>?,
        coroutineScope: CoroutineScope,
        notifyDispatcher: CoroutineDispatcher,
        fetchDispatcher: CoroutineDispatcher,
        boundaryCallback: BoundaryCallback<T>?,
        config: Config,
        key: K?
    ): PagedList<T> {
        val resolvedInitialPage = when (initialPage) {
            null -> {
                // Compatibility codepath - perform the initial load immediately, since caller
                // hasn't done it. We block in this case, but it's only used in the legacy path.
                val params = PagingSource.LoadParams.Refresh(
                    key,
                    config.initialLoadSizeHint,
                    config.enablePlaceholders,
                )
                runBlocking {
                    val initialResult = pagingSource.load(params)
                    when (initialResult) {
                        is PagingSource.LoadResult.Page -> initialResult
                        is PagingSource.LoadResult.Error -> throw initialResult.throwable
                        is PagingSource.LoadResult.Invalid ->
                            throw IllegalStateException(
                                "Failed to create PagedList. The provided PagingSource " +
                                    "returned LoadResult.Invalid, but a LoadResult.Page was " +
                                    "expected. To use a PagingSource which supports " +
                                    "invalidation, use a PagedList builder that accepts a " +
                                    "factory method for PagingSource or DataSource.Factory, " +
                                    "such as LivePagedList."
                            )
                    }
                }
            }
            else -> initialPage
        }
        return ContiguousPagedList(
            pagingSource,
            coroutineScope,
            notifyDispatcher,
            fetchDispatcher,
            boundaryCallback,
            config,
            resolvedInitialPage,
            key
        )
    }

So I inject a viewModelScope to start a nonblocking coroutine like

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Result> {
    try {
        return scope.async {
            val page = params.key ?: 1
            // network call to get repositories
            val repos = repository.getRepositories(query, page, 10)

            val results = repos.map { repo ->
                // uses repo to get its top contributor
                val contributor = repository.getTopContributor(repo.owner.username, 
repo.reponame)
                Result(repo.owner.url, repo.reponame, contributor.username?: "")
            }
            return@async LoadResult.Page(
                data = repoResults,
                prevKey = if (page == 1) null else page-1,
                nextKey = page + 1
            )
       }.await() as LoadResult<Int, Result>
    } catch (e: Exception) {
        return LoadResult.Error(e)
    }
}

Unfortunately scroll remains slow, so I ask

1.Is it true that load by default runs in a blocking fashion, despite getRepositories and getTopContributor switch to Dispatchers.IO, according to Why ‘withContext’ does not switch coroutines under ‘runBlocking’? it is

2.Since I need to make 1 network request to get repos, and each of those repos need to find their top contributor I am making page_size+1 requests. I’m looking for tips to improve my scroll performance as each page relies on these network requests. My Pager looks like

val pagingData: Flow<PagingData<RepoResult>> = Pager(
    config = PagingConfig(pageSize = PAGE_SIZE, prefetchDistance = 4 * PAGE_SIZE),
    pagingSourceFactory = { RepoResultPagingSource(repo, QUERY, viewModelScope) }
).flow.cachedIn(viewModelScope)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật