From d7ae9891ef079ef0aa6e2bba406306eec01b5df5 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Wed, 4 Nov 2026 00:45:24 +0100 Subject: [PATCH] Parallel save: stream entries when no worker thread starts Review point: with no worker thread the fallback built a whole in-memory zip per entry; it now writes each entry straight into the file like the serial writer, and the test covers that path. Co-Authored-By: Claude Sonnet 5.5 --- crates/formats/src/project_file/entries.rs | 8 ++++---- crates/formats/src/project_file/tests.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/formats/src/project_file/entries.rs b/crates/formats/src/project_file/entries.rs index a068e9b9..9e4c6d03 100644 --- a/crates/formats/src/project_file/entries.rs +++ b/crates/formats/src/project_file/entries.rs @@ -155,10 +155,10 @@ pub(super) mod parallel { let res = (|| -> Result<()> { for (i, w) in weights.iter().enumerate() { if started == 0 { - // No thread at all: compress here, one entry after the other. - let entry = slots.get(i).and_then(|s| lock(s).take()); - let bytes = compress(entry.ok_or_else(|| FormatError::Invalid("project entry missing".into()))?)?; - copy_entry(zip, bytes)?; + // No thread at all: stream the entry into the file like the serial writer does. + let entry = slots.get(i).and_then(|s| lock(s).take()).ok_or_else(|| FormatError::Invalid("project entry missing".into()))?; + zip.start_file(entry.name, entry.options).map_err(zip_err)?; + (entry.body)(zip)?; continue; } let done = { diff --git a/crates/formats/src/project_file/tests.rs b/crates/formats/src/project_file/tests.rs index eacc939a..48045f5d 100644 --- a/crates/formats/src/project_file/tests.rs +++ b/crates/formats/src/project_file/tests.rs @@ -269,7 +269,7 @@ fn parallel_save_writes_the_same_entries_as_serial() { let serial = serial_bytes(&pf); let want = payloads(&serial); assert!(want.len() > 10); - for (workers, budget) in [(2, u64::MAX), (4, u64::MAX), (8, 1), (3, 100_000)] { + for (workers, budget) in [(0, 1), (2, u64::MAX), (4, u64::MAX), (8, 1), (3, 100_000)] { let got = parallel_bytes(&pf, workers, budget); assert!(payloads(&got) == want, "{workers} workers, budget {budget}"); assert_same(&pf, &load_project_bytes(&got).unwrap());