Skip to content

Commit

Permalink
Small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc authored and dariolina committed Oct 21, 2024
1 parent 22cf49d commit 589a963
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions crates/subspace-farmer/src/single_disk_farm/plot_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,18 @@ impl DiskPlotCache {
return Ok(false);
};

let piece_index_bytes = piece_index.to_bytes();
let write_fut = tokio::task::spawn_blocking({
let piece = piece.clone();

move || {
file.write_all_at(&piece_index_bytes, element_offset)?;
file.write_all_at(piece.as_ref(), element_offset + PieceIndex::SIZE as u64)?;
file.write_all_at(
blake3_hash_list(&[&piece_index_bytes, piece.as_ref()]).as_ref(),
element_offset + PieceIndex::SIZE as u64 + Piece::SIZE as u64,
)
}
let piece_index_bytes = piece_index.to_bytes();
// File writes are read/write/modify internally, so combine all data here for more
// efficient write
let mut bytes = Vec::with_capacity(PieceIndex::SIZE + piece.len() + Blake3Hash::SIZE);
bytes.extend_from_slice(&piece_index_bytes);
bytes.extend_from_slice(piece.as_ref());
bytes.extend_from_slice(
blake3_hash_list(&[&piece_index_bytes, piece.as_ref()]).as_ref(),
);

move || file.write_all_at(&bytes, element_offset)
});

AsyncJoinOnDrop::new(write_fut, false).await??;
Expand Down

0 comments on commit 589a963

Please sign in to comment.