From 755934ca6dd1bd690b5bbcceb676443e14479133 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Sat, 3 Oct 2026 14:22:12 -0700 Subject: [PATCH] chore: Library::open_by takes its notifier boxed, compiling once instead of once per caller Its instantiations shrink from 392 KB to 128 KB. Release executables after the debug split: Linux x86_64 48.78 to 48.45 MB (-0.33), macOS aarch64 34.85 to 34.49 MB (-0.36). Assisted-by: claude-opus-5.5 --- crates/snowbound/src/library.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/snowbound/src/library.rs b/crates/snowbound/src/library.rs index 4c244307bcfda90d836cb91347026ed40c924531..c982db6c66f56685ceeefc807953928d26d6f408 100644 --- a/crates/snowbound/src/library.rs +++ b/crates/snowbound/src/library.rs @@ -796,14 +796,15 @@ impl Library { ) -> Result> { // The background may hold the replica for a step, which takes a network round trip, // or be making it as an offline copy. - self.open_by(path, notify, Instant::now() + TIMEOUT * 3) + self.open_by(path, Box::new(notify), Instant::now() + TIMEOUT * 3) } - /// `open`, waiting until `deadline` for whatever holds the section's replica. + /// `open`, waiting until `deadline` for whatever holds the section's replica. `notify` is + /// boxed to compile this once rather than once per caller's closure. fn open_by( &self, path: &str, - notify: impl Fn() + Send + 'static, + notify: Box, deadline: Instant, ) -> Result> { let notify = Arc::new(Mutex::new(notify)); @@ -901,7 +902,7 @@ impl Library { path: &str, notify: impl Fn() + Send + 'static, ) -> Result, Box> { - let section = self.open_by(path, notify, Instant::now())?; + let section = self.open_by(path, Box::new(notify), Instant::now())?; let replica = Arc::clone(section.replica()); self.keep(path, section); Ok(replica) -- 2.54.0