summaryrefslogtreecommitdiffstats
path: root/src/swarm/relay.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-24 20:28:36 +0200
committertv <tv@krebsco.de>2026-10-24 20:28:36 +0200
commit59c1511bcacedddc354e82033d523f459c6db5d4 (patch)
treefae84e91e1c7f4a98b2e99c79602ace059c6e211 /src/swarm/relay.rs
parent8e8aee67ef8dfa7c30a3734a4b6f5357c87f1a67 (diff)
cache heads
To reduce the number of write locks, heads are now cached.
Diffstat (limited to 'src/swarm/relay.rs')
-rw-r--r--src/swarm/relay.rs4
1 files changed, 4 insertions, 0 deletions
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.