Skip to content

Commit

Permalink
Replace parallel copy with sequential copy without pre-allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Feb 10, 2024
1 parent 1619150 commit 24bd4b0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions crates/subspace-proof-of-space/src/chiapos/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -787,18 +787,18 @@ where
let mut t_n = t_n.into_iter().flatten().collect::<Vec<_>>();
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,
Expand Down

0 comments on commit 24bd4b0

Please sign in to comment.