Improve performance of point equality checks #450
Merged
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.
Description
This PR optimizes how point equality checks are done for G1 and twedwards. The previous code transformed points to affine points and then did equality checks requiring two inverses. The new code avoids doing inverses. (I wonder if there was a reason for the current implementation, or if I might need to include something, LMK!).
I also added benchmark codes so we can compare the old and new code.
Type of change
Please delete options that are not relevant.
How has this been tested?
It runs all existing tests. If this equality check code change breaks the correct logic, it will probably make many tests fail.
How has this been benchmarked?
I created new benchmarks for equality checks. To test it against
master
, I backported them to the currentmaster
.This was run on
AMD Ryzen 7 3800XT 8-Core Processor
.For succinctness, I'll show the performance difference between BLS12-381 and Bandersnatch curves (but the implementation should fix all the other curves too).
Bandersnatch:
BLS12-381:
In both cases, we can see that
not_equal
bench is faster thanequal
which makes sense since we compareX
first andY
afterwards. In the old code, most of the time is dominated by inverses soequal
andnot_equal
have similar-ish perf.