Skip to content
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

perf: BW6 pairing computation using non-native Eval #1312

Merged
merged 15 commits into from
Nov 27, 2024
Merged

Conversation

ivokub
Copy link
Collaborator

@ivokub ivokub commented Nov 5, 2024

Description

This PR refactors the methods in the fields_bw6761 package to use the Field.Eval methods introduced in #1299. Depends on it being merged first.

Currently we use simple schoolbook multiplication formulas, but can have better performance with specialized formulas a la Toom-Cook etc. Currently didn't find a good way to give a multivariate representation to them.

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested?

  • TestSquareVariantsFp6
  • TestMulVariantsFp6
  • TestFp6Mul023By023Variants
  • TestFp6MulBy02345Variants
  • TestFp6CyclotomicSquareKarabina12345Variants

How has this been benchmarked?

  • Single Miller loop before: 6500708, now: 3841000
  • Single Miller loop fixed G2 before: 5344302, now: 2680076
  • FinalExp before: 5245872, now: 3362746
  • Full pairing before: 11486969, now: 6947630
  • Full pairing fixed G2 before: 10440385, now: 5888826

But keep in mind that I only measured single operations so they include range checks for the initial witness.

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@ivokub ivokub added the perf label Nov 5, 2024
@ivokub ivokub requested a review from yelhousni November 5, 2024 08:12
@ivokub ivokub self-assigned this Nov 5, 2024
@ivokub ivokub marked this pull request as ready for review November 22, 2024 22:46
Copy link
Contributor

@yelhousni yelhousni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!
I just did some experiments with the new Eval method + other variants of cyclotomic squares. It turns out that Granger-Scott Eval is better for 1 and 2 consecutive squares compared to Karabina. I pushed a commit.

@yelhousni
Copy link
Contributor

yelhousni commented Nov 26, 2024

Actually squareDirect is a re-implementation of mulDirect. Last commit specialises it to the evaluation of equal operands and saves some more scs. A full pairing is now 6931172 scs (16458 scs less).

@yelhousni
Copy link
Contributor

Also slight optimization of Karabina decompression Eval which saves an additional 11k scs. Full pairing is now 6,920,110 scs.

@yelhousni
Copy link
Contributor

Full pairing is now 6919174 scs.

@ivokub ivokub merged commit 76731ff into master Nov 27, 2024
5 checks passed
@ivokub ivokub deleted the perf/bw6-aseval branch November 27, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants