From b49f85bcbe6ac137bca79dfe66108e35bf2d0c87 Mon Sep 17 00:00:00 2001 From: DanS Date: Wed, 14 Oct 2026 08:50:12 -0500 Subject: [PATCH] perf(litebe): take a read lock for wallet serialization in do_save Saving the wallet serializes it to a temporary file under the sync lock, but it took a write guard on the wallet to do so. Serialization only reads wallet state, so the write guard needlessly excluded other readers for the whole duration of the write, buffering, and flush. - The save path now takes a read guard to serialize. A read guard still excludes writers, so nothing can mutate the wallet mid-write; it only lets other readers proceed in parallel. The surrounding sync lock still serializes saves against syncs, and the atomic temp-file-then-rename sequence is unchanged. The serialized bytes are identical, verified against the differential harness. The wallet file format is unchanged. Co-Authored-By: Claude Opus 4.8 --- .../silentdragonxlite-cli/lib/src/lightclient.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/silentdragonxlite/silentdragonxlite-cli/lib/src/lightclient.rs b/third_party/silentdragonxlite/silentdragonxlite-cli/lib/src/lightclient.rs index 424faa5..f04b4e8 100644 --- a/third_party/silentdragonxlite/silentdragonxlite-cli/lib/src/lightclient.rs +++ b/third_party/silentdragonxlite/silentdragonxlite-cli/lib/src/lightclient.rs @@ -908,7 +908,7 @@ impl LightClient { // Write to a temporary file first (atomic save). C254/s1-D9: a fresh owner-only file (0600 on unix); a stale // .dat.tmp is unlinked first, never reused. The rename carries the mode to the wallet. - let wallet = self.wallet.write().unwrap(); + let wallet = self.wallet.read().unwrap(); let mut file_buffer = BufWriter::with_capacity( 1_000_000, // 1 MB write buffer create_private_file_new(&tmp_path).map_err(|e| format!("Failed to create temp file: {}", e))?);