-
Notifications
You must be signed in to change notification settings - Fork 162
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
Seemingly needless clearing of array values #529
Comments
Ah, it seems that var runningSum, total g2JacExtended
runningSum.setInfinity()
total.setInfinity() (but the |
cc. @gbotrel, but it seems right that for G1 methods we can avoid zeroing the buckets. |
yes indeed, we can avoid zeroing the buckets twice with the affine msm. I suspect the code is here because some previous iterations had the buckets in extended jacobian coordinates; don't think it's going to be visible on benchmarks though. |
Looking at the code here: https://github.com/Consensys/gnark-crypto/blob/master/ecc/bls12-381/multiexp_jacobian.go#L108
The code waits for a go-ahead, to start processing the items. The wait, I presume, is to ensure that the worker doesn't interfere with other threads, or maybe that the inputs are not ready yet.
However, the local variable
buckets
is not shared, and thus it should be perfectly ok to do thebuckets[i].setInfinity()
-loop before waiting for the<-sem
.Looking into it a bit deeper, however, I see that the
buckets
is a newly stack-allocated array ofg2JacExtended
. For example, it might be[32]g2JacExtended
.The
g2JacExtended
is:and the
setInfinity()
isAs far as I can tell, the
setInfinity -> SetZero
methods, in the end, boil down to zeroinguint64
-arrays. This is not necessary in golang, newly allocated arrays (heap or stack) are always zeroed.So afaict the
buckets[i].setInfinity()
-loop can just be dropped. Perhaps I am missing something?The text was updated successfully, but these errors were encountered: