From 24bd4b0cbafaf724a51f9673e2787eb3344c2d19 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Sun, 11 Feb 2024 01:18:50 +0200 Subject: [PATCH] Replace parallel copy with sequential copy without pre-allocation --- .../src/chiapos/table.rs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/subspace-proof-of-space/src/chiapos/table.rs b/crates/subspace-proof-of-space/src/chiapos/table.rs index 84a76b8c38b..e3988794366 100644 --- a/crates/subspace-proof-of-space/src/chiapos/table.rs +++ b/crates/subspace-proof-of-space/src/chiapos/table.rs @@ -693,9 +693,9 @@ where let mut positions = Vec::with_capacity(t_n.len()); let mut metadatas = Vec::with_capacity(t_n.len()); - for (y, [left_position, right_position], metadata) in t_n { + for (y, position, metadata) in t_n { ys.push(y); - positions.push([left_position, right_position]); + positions.push(position); // Last table doesn't have metadata if metadata_size_bits(K, TABLE_NUMBER) > 0 { metadatas.push(metadata); @@ -787,18 +787,18 @@ where let mut t_n = t_n.into_iter().flatten().collect::>(); t_n.par_sort_unstable(); - let mut ys = vec![Default::default(); t_n.len()]; - let mut positions = vec![Default::default(); t_n.len()]; - let mut metadatas = vec![Default::default(); t_n.len()]; - - // Going in parallel saves a bit of time - t_n.into_par_iter() - .zip(ys.par_iter_mut().zip(&mut positions).zip(&mut metadatas)) - .for_each(|(input, output)| { - *output.0 .0 = input.0; - *output.0 .1 = input.1; - *output.1 = input.2; - }); + let mut ys = Vec::with_capacity(t_n.len()); + let mut positions = Vec::with_capacity(t_n.len()); + let mut metadatas = Vec::with_capacity(t_n.len()); + + for (y, position, metadata) in t_n { + ys.push(y); + positions.push(position); + // Last table doesn't have metadata + if metadata_size_bits(K, TABLE_NUMBER) > 0 { + metadatas.push(metadata); + } + } Self::Other { ys,