From ce64b7e549ffeb7d6968206f69de0ed45a0c45b9 Mon Sep 17 00:00:00 2001 From: Carl Johnsen Date: Mon, 21 Oct 2024 14:27:18 +0200 Subject: [PATCH 1/2] Sped up preliminary work in DoCompact. The first optimization was to add guards around the queries in case the second collection is empty (which is was when the slow path was found). The second optimization is to use a HashSet for the second collection, as this speeds up lookup, compared to using two List of string. --- .../Library/Main/Operation/CompactHandler.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Duplicati/Library/Main/Operation/CompactHandler.cs b/Duplicati/Library/Main/Operation/CompactHandler.cs index beea6d391..cbbd708fc 100644 --- a/Duplicati/Library/Main/Operation/CompactHandler.cs +++ b/Duplicati/Library/Main/Operation/CompactHandler.cs @@ -128,9 +128,16 @@ namespace Duplicati.Library.Main.Operation var downloadedVolumes = new List>(); //We start by deleting unused volumes to save space before uploading new stuff - var fullyDeleteable = (from v in remoteList - where report.DeleteableVolumes.Contains(v.Name) - select (IRemoteVolume)v).ToList(); + List fullyDeleteable = []; + if (report.DeleteableVolumes.Any()) + { + var deleteableVolumesAsHashes = new HashSet(report.DeleteableVolumes); + fullyDeleteable = + remoteList + .Where(n => deleteableVolumesAsHashes.Contains(n.Name)) + .Cast() + .ToList(); + } deletedVolumes.AddRange(DoDelete(db, backend, fullyDeleteable, ref transaction)); // This list is used to pick up unused volumes, @@ -141,9 +148,16 @@ namespace Duplicati.Library.Main.Operation if (report.ShouldCompact) { newvolindex?.StartVolume(newvol.RemoteFilename); - var volumesToDownload = (from v in remoteList - where report.CompactableVolumes.Contains(v.Name) - select (IRemoteVolume)v).ToList(); + List volumesToDownload = []; + if (report.CompactableVolumes.Any()) + { + var compactableVolumesAsHashSet = new HashSet(report.CompactableVolumes); + volumesToDownload = + remoteList + .Where(n => compactableVolumesAsHashSet.Contains(n.Name)) + .Cast() + .ToList(); + } using (var q = db.CreateBlockQueryHelper(transaction)) { From 20aea95007dc0c97f1364e8c162009933d2cdf07 Mon Sep 17 00:00:00 2001 From: Carl Johnsen Date: Mon, 21 Oct 2024 17:50:18 +0200 Subject: [PATCH 2/2] Fixed inconsistent variable naming --- Duplicati/Library/Main/Operation/CompactHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Duplicati/Library/Main/Operation/CompactHandler.cs b/Duplicati/Library/Main/Operation/CompactHandler.cs index cbbd708fc..443937f20 100644 --- a/Duplicati/Library/Main/Operation/CompactHandler.cs +++ b/Duplicati/Library/Main/Operation/CompactHandler.cs @@ -131,10 +131,10 @@ namespace Duplicati.Library.Main.Operation List fullyDeleteable = []; if (report.DeleteableVolumes.Any()) { - var deleteableVolumesAsHashes = new HashSet(report.DeleteableVolumes); + var deleteableVolumesAsHashSet = new HashSet(report.DeleteableVolumes); fullyDeleteable = remoteList - .Where(n => deleteableVolumesAsHashes.Contains(n.Name)) + .Where(n => deleteableVolumesAsHashSet.Contains(n.Name)) .Cast() .ToList(); }