Skip to content

Commit

Permalink
Support parallel constraint checking
Browse files Browse the repository at this point in the history
This puts in place support for parallel constraint checking using
go-routines.  The implementation was surprisingly straightforward, and
offers excellent improvements.
  • Loading branch information
DavePearce committed Jul 26, 2024
1 parent 44824f5 commit ac35385
Showing 1 changed file with 1 addition and 43 deletions.
44 changes: 1 addition & 43 deletions pkg/schema/schemas.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package schema

import (
"fmt"
"time"

tr "github.com/consensys/go-corset/pkg/trace"
)

Expand Down Expand Up @@ -63,7 +60,6 @@ func RequiredSpillage(schema Schema) uint {
// specifically, that means computing the actual values for any assignments.
// Observe that assignments have to be computed in the correct order.
func ExpandTrace(schema Schema, trace tr.Trace) error {
start := time.Now()
// Compute each assignment in turn
for i := schema.Assignments(); i.HasNext(); {
// Get ith assignment
Expand All @@ -73,7 +69,6 @@ func ExpandTrace(schema Schema, trace tr.Trace) error {
return err
}
}
fmt.Printf("Trace expansion took %.2fs\n", time.Since(start).Seconds())
// Done
return nil
}
Expand All @@ -84,46 +79,11 @@ func ExpandTrace(schema Schema, trace tr.Trace) error {
// which does not hold.
//
//nolint:revive
func Accepts2(schema Schema, trace tr.Trace) error {
var err error
start := time.Now()
// Determine how many constraints
n := schema.Constraints().Count()
fmt.Printf("Beginning constraint checking (%d constraints)\n", n)
// Construct a channel with enough s
//c := make(chan error, 1)
// Check each constraint in turn
for i := schema.Constraints(); i.HasNext(); {
// Get ith constraint
ith := i.Next()
// Check it holds (or report an error)
if e := ith.Accepts(trace); e != nil {
err = e
}
// go func() {
// c <- ith.Accepts(trace)
// }()
}
// // Read responses back from each constraint.
// for i := uint(0); i < n; i++ {
// // Read from channel
// if e := <-c; e != nil {
// err = e
// }
// }
//
fmt.Printf("Constraint checking tool %.2fs\n", time.Since(start).Seconds())
// Success
return err
}

func Accepts(schema Schema, trace tr.Trace) error {
var err error
start := time.Now()
// Determine how many constraints
n := schema.Constraints().Count()
fmt.Printf("Beginning constraint checking (%d constraints)\n", n)
// Construct a channel with enough s
// Construct a communication channel for errors.
c := make(chan error, 100)
// Check each constraint in turn
for i := schema.Constraints(); i.HasNext(); {
Expand All @@ -142,8 +102,6 @@ func Accepts(schema Schema, trace tr.Trace) error {
err = e
}
}
//
fmt.Printf("Constraint checking tool %.2fs\n", time.Since(start).Seconds())
// Success
return err
}
Expand Down

0 comments on commit ac35385

Please sign in to comment.