Merge pull request #66 from scroll-tech/speedup-param-read

Speedup param read
This commit is contained in:
Carlos Pérez 2022-05-03 15:28:43 +02:00 committed by GitHub
commit ae2aa5bce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 7 deletions

View File

@ -179,12 +179,23 @@ impl<C: CurveAffine> Params<C> {
let k = u32::from_le_bytes(k); let k = u32::from_le_bytes(k);
let n = 1 << k; let n = 1 << k;
let g: Vec<C> = (0..n) let load_points_from_file_parallelly = |reader: &mut R| -> io::Result<Vec<C>> {
.map(|_| C::read(&mut reader)) let mut points_compressed: Vec<C::Repr> = vec![C::Repr::default(); n];
.collect::<Result<_, _>>()?; for points_compressed in points_compressed.iter_mut() {
let g_lagrange: Vec<C> = (0..n) reader.read_exact((*points_compressed).as_mut())?;
.map(|_| C::read(&mut reader)) }
.collect::<Result<_, _>>()?;
let mut points = vec![C::default(); n];
parallelize(&mut points, |points, chunks| {
for (i, point) in points.iter_mut().enumerate() {
*point = Option::from(C::from_bytes(&points_compressed[chunks + i])).unwrap();
}
});
Ok(points)
};
let g = load_points_from_file_parallelly(&mut reader)?;
let g_lagrange = load_points_from_file_parallelly(&mut reader)?;
let mut additional_data_len = [0u8; 4]; let mut additional_data_len = [0u8; 4];
reader.read_exact(&mut additional_data_len[..])?; reader.read_exact(&mut additional_data_len[..])?;
@ -195,7 +206,7 @@ impl<C: CurveAffine> Params<C> {
Ok(Params { Ok(Params {
k, k,
n, n: n as u64,
g, g,
g_lagrange, g_lagrange,
additional_data, additional_data,