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/peer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/swarm/peer.rs') diff --git a/src/swarm/peer.rs b/src/swarm/peer.rs index dd70bbb..3d7da32 100644 --- a/src/swarm/peer.rs +++ b/src/swarm/peer.rs @@ -108,12 +108,12 @@ pub(crate) async fn send_ping(state: &AppState, peer: &str) -> Result<()> { /// Our keepalive for `peer`. pub(crate) async fn local_keepalive(state: &AppState, peer: &str) -> transport::Keepalive { - // AutoCommit::get_heads takes &mut self (it closes the pending transaction). - // Heads and epoch come from the same locked replica, so they always match. + // Heads and epoch come from the same locked replica, so they always match. The heads + // are cached (`Replica`), so the read lock is enough. let (heads, epoch) = { - let mut replica = state.doc.write().await; + let replica = state.doc.read().await; ( - transport::HeadsSummary::of(replica.doc.get_heads()), + transport::HeadsSummary::of(replica.heads().to_vec()), replica.epoch, ) }; -- cgit v1.3.1