From 2b9194cf424973b9efeafc2b6570d3381cb3cec4 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Sat, 12 Oct 2024 13:54:47 +0800 Subject: [PATCH] perf: optimize shrink frontiers --- crates/loro-internal/src/version.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/loro-internal/src/version.rs b/crates/loro-internal/src/version.rs index f1eac0e6..e178f210 100644 --- a/crates/loro-internal/src/version.rs +++ b/crates/loro-internal/src/version.rs @@ -1031,6 +1031,11 @@ pub fn shrink_frontiers(last_ids: &[ID], dag: &AppDag) -> Result let mut last_ids = { let ids = filter_duplicated_peer_id(last_ids); + if last_ids.len() == 1 { + frontiers.push(last_ids[0]); + return Ok(frontiers); + } + let mut last_ids = Vec::with_capacity(ids.len()); for id in ids { let Some(lamport) = dag.get_lamport(&id) else { @@ -1042,11 +1047,6 @@ pub fn shrink_frontiers(last_ids: &[ID], dag: &AppDag) -> Result last_ids }; - if last_ids.len() == 1 { - frontiers.push(last_ids[0].id()); - return Ok(frontiers); - } - // Iterate from the greatest lamport to the smallest last_ids.sort_by_key(|x| x.lamport); for id in last_ids.iter().rev() {