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

chore: add Iterative version of FFT #97

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

kevaundray
Copy link
Contributor

No description provided.

@kevaundray
Copy link
Contributor Author

Before this change I get:

BenchmarkFftFr4096-10    	     622	   1980674 ns/op	 3145754 B/op	   12285 allocs/op

After this change I get:

BenchmarkFftFr4096-10    	     960	   1223009 ns/op	  131553 B/op	      25 allocs/op

@kevaundray
Copy link
Contributor Author

We could improve a bit more by precomputing the twiddle factor too

@kevaundray
Copy link
Contributor Author

For compute_cells_and_kzg_proofs:

Before(master):

BenchmarkComputeCellsAndKZGProofs-10    	       8	 144308682 ns/op	20540281 B/op	   82067 allocs/op

and after(this branch):

BenchmarkComputeCellsAndKZGProofs-10    	       7	 146054030 ns/op	 7310843 B/op	   21866 allocs/op

@kevaundray
Copy link
Contributor Author

So its roughly the same performance but the newer version is more memory efficient

@kevaundray
Copy link
Contributor Author

Parallelizing fftG1 gives:

BenchmarkComputeCellsAndKZGProofs-10    	      10	 112199275 ns/op	 7333895 B/op	   22402 allocs/op

@kevaundray
Copy link
Contributor Author

Bench code:

func BenchmarkFftFr4096(b *testing.B) {
	// Set up the polynomial of size 4096
	n := uint64(4096)
	polyMonomial := make([]fr.Element, n)
	for i := uint64(0); i < n; i++ {
		polyMonomial[i] = fr.NewElement(uint64(rand.Uint32()))
	}

	// Create the domain
	d := NewDomain(n)

	// Run the benchmark
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		d.FftFr(polyMonomial)
	}
}
package goethkzg_test

import (
	"testing"

	"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
	goethkzg "github.com/crate-crypto/go-eth-kzg"
)

func BenchmarkComputeCellsAndKZGProofs(b *testing.B) {
	// Setup: Create a Context and prepare input data
	// ctx := NewContext() // Replace with actual initialization
	polyCoeff := make([]fr.Element, goethkzg.ScalarsPerBlob)
	for i := 0; i < goethkzg.ScalarsPerBlob; i++ {
		element := fr.NewElement(uint64(i))
		element.Neg(&element)
		polyCoeff[i] = element
	}
	blob := goethkzg.SerializePoly(polyCoeff)

	// Reset the timer before the loop
	b.ResetTimer()

	// Run the benchmark
	for i := 0; i < b.N; i++ {
		cells, proofs, err := ctx.ComputeCellsAndKZGProofs(blob, 0)
		if err != nil {
			b.Fatal(err)
		}
		// Optionally use cells and proofs to prevent compiler optimization
		// Use the results in a way that can't be optimized out
		if cells[0] == nil {
			b.StopTimer()
			b.Fatal("Unexpected nil result")
			b.StartTimer()
		}
		if (proofs[0] == goethkzg.KZGProof{}) {
			b.StopTimer()
			b.Fatal("Unexpected nil result")
			b.StartTimer()
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant