From acc78868a7d427d2ace4cf679f1b1b87b0e689c8 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Sat, 8 Feb 2025 09:20:16 -0600 Subject: [PATCH 1/2] Add new VerifyCellKZGProofBatchParallel benchmark --- bindings/go/main_test.go | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/bindings/go/main_test.go b/bindings/go/main_test.go index 195e316ea..aa8b2de77 100644 --- a/bindings/go/main_test.go +++ b/bindings/go/main_test.go @@ -842,4 +842,70 @@ func Benchmark(b *testing.B) { } }) } + + b.Run("VerifyCellKZGProofBatchParallel", func(b *testing.B) { + // Determine the ideal group count + numGroups := runtime.NumCPU() + if numGroups > length { + numGroups = length + } + // Decrementing until each group has equal blobs + for numGroups > 0 && length%numGroups != 0 { + numGroups-- + } + blobsPerGroup := length / numGroups + + // Pre-partition the cell data into groups + type groupData struct { + cellCommitments []Bytes48 + cellIndices []uint64 + cells []Cell + cellProofs []Bytes48 + } + groups := make([]groupData, numGroups) + for group := 0; group < numGroups; group++ { + startBlob := group * blobsPerGroup + endBlob := startBlob + blobsPerGroup + + var groupCommitments []Bytes48 + var groupIndices []uint64 + var groupCells []Cell + var groupProofs []Bytes48 + + for blobIndex := startBlob; blobIndex < endBlob; blobIndex++ { + for cellIndex, cell := range blobCells[blobIndex] { + groupCommitments = append(groupCommitments, commitments[blobIndex]) + groupIndices = append(groupIndices, uint64(cellIndex)) + groupCells = append(groupCells, cell) + groupProofs = append(groupProofs, blobCellProofs[blobIndex][cellIndex]) + } + } + groups[group] = groupData{ + cellCommitments: groupCommitments, + cellIndices: groupIndices, + cells: groupCells, + cellProofs: groupProofs, + } + } + + b.ResetTimer() + for n := 0; n < b.N; n++ { + var wg sync.WaitGroup + for group := 0; group < numGroups; group++ { + wg.Add(1) + go func(group int) { + defer wg.Done() + ok, err := VerifyCellKZGProofBatch( + groups[group].cellCommitments, + groups[group].cellIndices, + groups[group].cells, + groups[group].cellProofs, + ) + require.NoError(b, err) + require.True(b, ok) + }(group) + } + wg.Wait() + } + }) } From 20b07d76f5a921e5405293b1dd315f93d389cd47 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Sat, 8 Feb 2025 09:39:37 -0600 Subject: [PATCH 2/2] Move to a better spot --- bindings/go/main_test.go | 74 ++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/bindings/go/main_test.go b/bindings/go/main_test.go index aa8b2de77..e425e8830 100644 --- a/bindings/go/main_test.go +++ b/bindings/go/main_test.go @@ -806,43 +806,6 @@ func Benchmark(b *testing.B) { } }) - for i := 1; i <= length; i *= 2 { - b.Run(fmt.Sprintf("VerifyRows(count=%v)", i), func(b *testing.B) { - var cellCommitments []Bytes48 - var cellIndices []uint64 - var cells []Cell - var cellProofs []Bytes48 - for rowIndex, blobCell := range blobCells { - if rowIndex == i { - break - } - for cellIndex, cell := range blobCell { - cellCommitments = append(cellCommitments, commitments[rowIndex]) - cellIndices = append(cellIndices, uint64(cellIndex)) - cells = append(cells, cell) - cellProofs = append(cellProofs, blobCellProofs[rowIndex][cellIndex]) - } - } - b.ResetTimer() - for n := 0; n < b.N; n++ { - ok, err := VerifyCellKZGProofBatch(cellCommitments, cellIndices, cells, cellProofs) - require.NoError(b, err) - require.True(b, ok) - } - }) - } - - for i := 1; i <= CellsPerExtBlob; i *= 2 { - cellCommitments, cellIndices, cells, cellProofs := getColumns(commitments[:], blobCells[:], blobCellProofs[:], i) - b.Run(fmt.Sprintf("VerifyColumns(count=%v)", i), func(b *testing.B) { - for n := 0; n < b.N; n++ { - ok, err := VerifyCellKZGProofBatch(cellCommitments, cellIndices, cells, cellProofs) - require.NoError(b, err) - require.True(b, ok) - } - }) - } - b.Run("VerifyCellKZGProofBatchParallel", func(b *testing.B) { // Determine the ideal group count numGroups := runtime.NumCPU() @@ -908,4 +871,41 @@ func Benchmark(b *testing.B) { wg.Wait() } }) + + for i := 1; i <= length; i *= 2 { + b.Run(fmt.Sprintf("VerifyRows(count=%v)", i), func(b *testing.B) { + var cellCommitments []Bytes48 + var cellIndices []uint64 + var cells []Cell + var cellProofs []Bytes48 + for rowIndex, blobCell := range blobCells { + if rowIndex == i { + break + } + for cellIndex, cell := range blobCell { + cellCommitments = append(cellCommitments, commitments[rowIndex]) + cellIndices = append(cellIndices, uint64(cellIndex)) + cells = append(cells, cell) + cellProofs = append(cellProofs, blobCellProofs[rowIndex][cellIndex]) + } + } + b.ResetTimer() + for n := 0; n < b.N; n++ { + ok, err := VerifyCellKZGProofBatch(cellCommitments, cellIndices, cells, cellProofs) + require.NoError(b, err) + require.True(b, ok) + } + }) + } + + for i := 1; i <= CellsPerExtBlob; i *= 2 { + cellCommitments, cellIndices, cells, cellProofs := getColumns(commitments[:], blobCells[:], blobCellProofs[:], i) + b.Run(fmt.Sprintf("VerifyColumns(count=%v)", i), func(b *testing.B) { + for n := 0; n < b.N; n++ { + ok, err := VerifyCellKZGProofBatch(cellCommitments, cellIndices, cells, cellProofs) + require.NoError(b, err) + require.True(b, ok) + } + }) + } }