mirror of https://github.com/zcash/halo2.git
feat: Cache table when same identifier and improve permutation checks in `MockProver`
This commit is contained in:
parent
f08632016f
commit
984105592c
|
@ -5,6 +5,7 @@ use std::collections::HashSet;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::ops::{Add, Mul, Neg, Range};
|
use std::ops::{Add, Mul, Neg, Range};
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use ff::Field;
|
use ff::Field;
|
||||||
|
|
||||||
|
@ -701,6 +702,8 @@ impl<F: FieldExt> MockProver<F> {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut cached_table = Vec::new();
|
||||||
|
let mut cached_table_identifier = Vec::new();
|
||||||
// Check that all lookups exist in their respective tables.
|
// Check that all lookups exist in their respective tables.
|
||||||
let lookup_errors =
|
let lookup_errors =
|
||||||
self.cs
|
self.cs
|
||||||
|
@ -760,26 +763,36 @@ impl<F: FieldExt> MockProver<F> {
|
||||||
.map(move |c| load(c, self.usable_rows.end - 1))
|
.map(move |c| load(c, self.usable_rows.end - 1))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// In the real prover, the lookup expressions are never enforced on
|
let table_identifier = lookup
|
||||||
// unusable rows, due to the (1 - (l_last(X) + l_blind(X))) term.
|
.table_expressions
|
||||||
let mut table: Vec<Vec<_>> = self
|
.iter()
|
||||||
.usable_rows
|
.map(Expression::identifier)
|
||||||
.clone()
|
.collect::<Vec<_>>();
|
||||||
.filter_map(|table_row| {
|
if table_identifier != cached_table_identifier {
|
||||||
let t = lookup
|
cached_table_identifier = table_identifier;
|
||||||
.table_expressions
|
|
||||||
.iter()
|
|
||||||
.map(move |c| load(c, table_row))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if t != fill_row {
|
// In the real prover, the lookup expressions are never enforced on
|
||||||
Some(t)
|
// unusable rows, due to the (1 - (l_last(X) + l_blind(X))) term.
|
||||||
} else {
|
cached_table = self
|
||||||
None
|
.usable_rows
|
||||||
}
|
.clone()
|
||||||
})
|
.filter_map(|table_row| {
|
||||||
.collect();
|
let t = lookup
|
||||||
table.sort_unstable();
|
.table_expressions
|
||||||
|
.iter()
|
||||||
|
.map(move |c| load(c, table_row))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if t != fill_row {
|
||||||
|
Some(t)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
cached_table.sort_unstable();
|
||||||
|
}
|
||||||
|
let table = &cached_table;
|
||||||
|
|
||||||
let mut inputs: Vec<(Vec<_>, usize)> = lookup_input_row_ids
|
let mut inputs: Vec<(Vec<_>, usize)> = lookup_input_row_ids
|
||||||
.clone()
|
.clone()
|
||||||
|
|
Loading…
Reference in New Issue