Skip to content

Commit

Permalink
Merge pull request #52 from SiaFoundation/chris/sector-roots-speedup
Browse files Browse the repository at this point in the history
Avoid allocation in sector roots
  • Loading branch information
n8maninger authored Sep 26, 2024
2 parents 5af7f3a + 9b3df56 commit f659654
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/rhp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ pub fn sector_root(sector: &[u8]) -> Hash256 {
.map(|chunk| sum_leaf(&params, chunk))
.collect::<Vec<_>>();

let mut step_size = 1;
while step_size < tree_hashes.len() {
let mut chunk_size = 2;
while chunk_size <= tree_hashes.len() {
tree_hashes
.par_iter_mut()
.step_by(step_size)
.chunks(2)
.for_each(|mut nodes| {
*nodes[0] = sum_node(&params, nodes[0], nodes[1]);
.par_chunks_exact_mut(chunk_size)
.for_each(|nodes| {
nodes[0] = sum_node(&params, &nodes[0], &nodes[nodes.len() / 2]);
});
step_size *= 2;
chunk_size *= 2;
}
Hash256::from(tree_hashes[0])
}
Expand Down

0 comments on commit f659654

Please sign in to comment.