Inefficient vector capacity
In the function keccak_inputs_from_ubv_instances
in the file circuits/src/keccak/utils.rs, there is the following vector defined with capacity:
let mut keccak_inputs =
Vec::with_capacity(ubv_instances.len() * inputs_per_proof);
However, keccak_inputs
will ultimately have ubv_instances.len() * inner_batch_size
elements. Thus, if inputs_per_proof < inner_batch_size
, additional allocations will need to be performed. If instead inputs_per_proof > inner_batch_size
, then an unnecessary amount of memory will be allocated for this vector. We thus recommend to change the allocated capacity:
let mut keccak_inputs =
- Vec::with_capacity(ubv_instances.len() * inputs_per_proof);
+ Vec::with_capacity(ubv_instances.len() * inner_batch_size);