mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-20 06:20:50 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
11d672661f
commit
d7ae9891ef
2 files changed
+5
-5
No files matched your search
@@ -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 = {
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user