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
commit111444d956e98d348244326d3bf6c34da62b96d7 (patch)
treeb0f54e27ce0b4d8e4074a2ba44715dfa5afc1313 /src/swarm/relay.rs
parent7cc4d0f3ae697e6429b6d237fd477297b21add94 (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.