performance improvements#1307
Merged
Merged
Conversation
8a18e60 to
bd2c21d
Compare
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com> # Conflicts: # go.mod
a99ac22 to
2e1fcbd
Compare
HayimShaul
reviewed
Feb 5, 2026
Comment on lines
+48
to
+62
| func Zero(c *math.Curve) *math.Zr { | ||
| return NewCachedZrFromInt(c, 0) | ||
| } | ||
|
|
||
| // One returns the curve element representing 1 in Zr. It prefers the | ||
| // cached value when present. | ||
| func One(c *math.Curve) *math.Zr { | ||
| return NewCachedZrFromInt(c, 1) | ||
| } | ||
|
|
||
| // Two returns the curve element representing 2 in Zr. It prefers the | ||
| // cached value when present. | ||
| func Two(c *math.Curve) *math.Zr { | ||
| return NewCachedZrFromInt(c, 2) | ||
| } |
Contributor
There was a problem hiding this comment.
Doesn't a small number X simply correspond to (0,0,...,X) in math.Zr? How much does caching these values save?
Contributor
Author
There was a problem hiding this comment.
zero, one, and two were instantiated multiple times in the code. Having them pre-generated once and for all saves a lot of allocations in the long run.
HayimShaul
reviewed
Feb 5, 2026
| if !ok { | ||
| logger.Warnf("no hit for [%d:%d]", c.ID(), i) | ||
| two := c.NewZrFromUint64(2) | ||
| return two.PowMod(c.NewZrFromUint64(i)) |
Contributor
There was a problem hiding this comment.
why should this happen after you have populated the cache?
Contributor
There was a problem hiding this comment.
If this happens a lot, maybe find a high power of 2 that is in the cache and multiply it by the factor that it is missing?
Contributor
There was a problem hiding this comment.
Also, there's Exp(Element, Big.Int) I think this will be faster than converting to Zr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces the following improvements:
This PR depends on IBM/mathlib#42