From 8ad00e11764dfec835995a77d4514d6e0b45b1f1 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Tue, 4 Jun 2024 23:12:03 +0000 Subject: [PATCH] Improve performance of large number of package downloads For a reposync of Fedora 40, this reduces the loop in lr_download_packages() from taking ~61 seconds to ~1second. Signed-off-by: Stewart Smith --- librepo/package_downloader.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/librepo/package_downloader.c b/librepo/package_downloader.c index 353cac81..aa6d94b7 100644 --- a/librepo/package_downloader.c +++ b/librepo/package_downloader.c @@ -404,8 +404,13 @@ lr_download_packages(GSList *targets, FALSE, FALSE); - downloadtargets = g_slist_append(downloadtargets, downloadtarget); + downloadtargets = g_slist_prepend(downloadtargets, downloadtarget); } + /* + * Since g_slist_append() has to traverse the list to the end, we use + * g_slist_prepend() above, and reverse the lists now. + */ + downloadtargets = g_slist_reverse(downloadtargets); // Do Fastest Mirror resolving for all handles in one shot if (fmr_handles) {