-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: plonk frontend filter common cases of duplicate constraints #539
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I'm still amazed at the savings this PR gives.
I think long-term maybe should consider two approaches:
- also store other add constraints with same wires (maybe instead of map[uint64]int use map[uint64][]int and then do linear scan?
- maybe put some fast inclusion checker in front of map (a la Bloom filter). Maybe helps with the perf?
Suggested edit: diff --git a/frontend/internal/expr/linear_expression.go b/frontend/internal/expr/linear_expression.go
index 3ef4c90c..21b3b8f1 100644
--- a/frontend/internal/expr/linear_expression.go
+++ b/frontend/internal/expr/linear_expression.go
@@ -38,17 +38,6 @@ func (t Term) WireID() int {
}
func (t Term) HashCode() uint64 {
- // hashCode := t.Coeff[0] * 17
- // hashCode *= 31
- // hashCode += t.Coeff[1] * 17
- // hashCode *= 31
- // hashCode += t.Coeff[2] * 17
- // hashCode *= 31
- // hashCode += t.Coeff[3] * 17
- // hashCode *= 31
- // hashCode <<= 29
- // hashCode |= uint64(t.VID) // << 2**29;
- // return hashCode
return t.Coeff[0]*29 + uint64(t.VID<<12)
}
|
re: savings; I think some of it may be reusing the wires in non-obvious situations. like we do a bit more than just "duplicate constraints", we detect them up to a factor (for additions) & with different coeffs (for mul). |
@ivokub re bloom filter; I don't think it can beat the |
we may improve CPU but make it worse for memory by deriving something from this idea, like... a slice of uint64 of len == nb variables. |
TLDR;
Perf
scs.Builder
seems to be ~15% slower (std/groth16bls12377 test)Same logic with mul gates; except we are more permissive with xa and xb coefficients since we can always re-use the existing wire in that case.