From 8d330b5e63260aa21f1730fd57430cc3f506e4df Mon Sep 17 00:00:00 2001 From: porcuquine Date: Wed, 1 Jul 2020 09:03:08 -0700 Subject: [PATCH] Allocate less. --- filecoin-proofs/src/api/seal.rs | 19 +++---------------- .../porep/src/stacked/vanilla/proof.rs | 7 ++++--- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/filecoin-proofs/src/api/seal.rs b/filecoin-proofs/src/api/seal.rs index b3538b5b5b..9b9efecb22 100644 --- a/filecoin-proofs/src/api/seal.rs +++ b/filecoin-proofs/src/api/seal.rs @@ -1,6 +1,5 @@ use std::fs::{self, metadata, File, OpenOptions}; use std::io::prelude::*; -use std::io::BufWriter; use std::path::{Path, PathBuf}; use anyhow::{ensure, Context, Result}; @@ -780,24 +779,12 @@ pub fn fauxrep_aux< cache_path: R, out_path: S, ) -> Result { - let sector_bytes = PaddedBytesAmount::from(porep_config).0 as usize; + let sector_bytes = PaddedBytesAmount::from(porep_config).0; { // Create a sector full of null bytes at `out_path`. - let chunk_size = usize::min(sector_bytes, 1024); - let chunk = vec![0; chunk_size]; - let chunk_count = sector_bytes / chunk_size; - assert_eq!( - 0, - sector_bytes % chunk_size, - "sector size is not an even number of KiB" - ); - let file = File::create(&out_path)?; - let mut buf = BufWriter::with_capacity(chunk.len(), file); - for _ in 0..chunk_count { - buf.write_all(&chunk)?; - } + file.set_len(sector_bytes)?; } let fake_comm_c = ::Domain::random(&mut rng); @@ -805,7 +792,7 @@ pub fn fauxrep_aux< fake_comm_c, out_path, &cache_path, - sector_bytes, + sector_bytes as usize, )?; let p_aux_path = cache_path.as_ref().join(CacheKey::PAux.to_string()); diff --git a/storage-proofs/porep/src/stacked/vanilla/proof.rs b/storage-proofs/porep/src/stacked/vanilla/proof.rs index 48fd7bc30f..fe7ac93dca 100644 --- a/storage-proofs/porep/src/stacked/vanilla/proof.rs +++ b/storage-proofs/porep/src/stacked/vanilla/proof.rs @@ -1194,17 +1194,18 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr ) .expect("failed to create TreeBuilder"); + // Allocate zeros once and reuse. + let zero_leaves: Vec = vec![Fr::zero(); max_gpu_tree_batch_size]; for (i, config) in configs.iter().enumerate() { let mut consumed = 0; while consumed < nodes_count { let batch_size = usize::min(max_gpu_tree_batch_size, nodes_count - consumed); - let zero_leaves: Vec = vec![Fr::zero(); batch_size]; consumed += batch_size; if consumed != nodes_count { tree_builder - .add_leaves(zero_leaves.as_slice()) + .add_leaves(&zero_leaves[0..batch_size]) .expect("failed to add leaves"); continue; }; @@ -1217,7 +1218,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr ); let (_, tree_data) = tree_builder - .add_final_leaves(&zero_leaves) + .add_final_leaves(&zero_leaves[0..batch_size]) .expect("failed to add final leaves"); let tree_data_len = tree_data.len(); let cache_size = get_merkle_tree_cache_size(