From 59c1511bcacedddc354e82033d523f459c6db5d4 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 24 Oct 2026 20:28:36 +0200 Subject: cache heads To reduce the number of write locks, heads are now cached. --- src/swarm/relay.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/swarm/relay.rs') diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs index 454a46a..492b59d 100644 --- a/src/swarm/relay.rs +++ b/src/swarm/relay.rs @@ -52,6 +52,10 @@ pub(crate) async fn pull_if_behind(state: &AppState, peer: &str, remote: &transp if remote.epoch != state.local_epoch() || !topology::is_neighbour(state, peer) { return; } + // The common case, the same heads, needs only the cached heads (read lock). + if HeadsSummary::of(state.doc.read().await.heads().to_vec()) == remote.heads { + return; + } let missing = match &remote.heads { HeadsSummary::Heads(heads) => { // AutoCommit's lookups take &mut self. -- cgit v1.3.1