Open protolambda opened 3 years ago
Hey @kilic, can we productionize this improvement? I can polish the code and make the PR ready if you can give some initial feedback?
@protolambda Thanks! Sure we can add this improvement.
I'm happy with switching to []PointG1/2
. Can you also apply the same to the MultiExpBig
function?
Constant window size and smaller type also sound good to me. It seems like window size 4
gives the best result for G1 and both wnaf and glv multiplications. And again for both wnaf and glv in G2 there is a tiny difference between 3
and 4
. Shared my results below and includes Fr
type.
G1 wnaf
BenchmarkG1MulWNAF/Fr,_window:_1-8 8690 134234 ns/op
BenchmarkG1MulWNAF/Fr,_window:_2-8 8943 127914 ns/op
BenchmarkG1MulWNAF/Fr,_window:_3-8 9138 125774 ns/op
BenchmarkG1MulWNAF/Fr,_window:_4-8 9255 122877 ns/op
BenchmarkG1MulWNAF/Fr,_window:_5-8 9462 126541 ns/op
G1 glv
BenchmarkG1MulGLV/Fr,_window:_1-8 10000 100515 ns/op
BenchmarkG1MulGLV/Fr,_window:_2-8 13446 89177 ns/op
BenchmarkG1MulGLV/Fr,_window:_3-8 13623 87922 ns/op
BenchmarkG1MulGLV/Fr,_window:_4-8 13941 85936 ns/op
BenchmarkG1MulGLV/Fr,_window:_5-8 13285 89931 ns/op
BenchmarkG1MulGLV/Fr,_window:_6-8 10000 103667 ns/op
G2 wnaf
BenchmarkG2MulWNAF/Fr,_window:_1-8 3534 333858 ns/op
BenchmarkG2MulWNAF/Fr,_window:_2-8 3535 327158 ns/op
BenchmarkG2MulWNAF/Fr,_window:_3-8 3783 309761 ns/op
BenchmarkG2MulWNAF/Fr,_window:_4-8 3913 302329 ns/op
BenchmarkG2MulWNAF/Fr,_window:_5-8 3908 303272 ns/op
BenchmarkG2MulWNAF/Fr,_window:_6-8 3643 322695 ns/op
G1 glv
BenchmarkG2MulGLV/Fr,_window:_1-8 4539 232194 ns/op
BenchmarkG2MulGLV/Fr,_window:_2-8 5492 211677 ns/op
BenchmarkG2MulGLV/Fr,_window:_3-8 5928 195555 ns/op
BenchmarkG2MulGLV/Fr,_window:_4-8 6051 195011 ns/op
BenchmarkG2MulGLV/Fr,_window:_5-8 5682 205829 ns/op
BenchmarkG2MulGLV/Fr,_window:_6-8 4831 241982 ns/op
This is experimental, just for illustration, it needs review, and maybe some of the changes are worthwhile.
The wnaf type:
int
as element type, even though for the default window size, it could fit in aint8
, a 8x size reductionint8
, but that's fine.And
MultiExp
has a[]*PointG1
input, while I much prefer[]PointG1
, since we allocate large arrays of these, and there is no use for an unnecessary extra layer of indirection. Or maybe an alternative function could be exposed, with this input type?Benchmark: