From aa3b0204bd3430104cb62fa13c42a8be0a338405 Mon Sep 17 00:00:00 2001 From: marvin-j97 Date: Fri, 23 Aug 2024 00:30:21 +0200 Subject: [PATCH] perf: fast path if no blob files are dropped --- src/value_log.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/value_log.rs b/src/value_log.rs index b0389d7..2e74f86 100644 --- a/src/value_log.rs +++ b/src/value_log.rs @@ -309,18 +309,22 @@ impl ValueLog { .cloned() .collect::>(); - let disk_space: u64 = segments.iter().map(|x| x.meta.compressed_bytes).sum(); + let bytes_freed = segments.iter().map(|x| x.meta.compressed_bytes).sum(); let ids = segments.iter().map(|x| x.id).collect::>(); - log::info!("Dropping stale blob files: {ids:?}"); - self.manifest.drop_segments(&ids)?; + if ids.is_empty() { + log::trace!("No blob files to drop"); + } else { + log::info!("Dropping stale blob files: {ids:?}"); + self.manifest.drop_segments(&ids)?; - for segment in segments { - std::fs::remove_file(&segment.path)?; + for segment in segments { + std::fs::remove_file(&segment.path)?; + } } - Ok(disk_space) + Ok(bytes_freed) } /// Marks some segments as stale.