ethsnarks icon indicating copy to clipboard operation
ethsnarks copied to clipboard

Avoid copy constructors to improve performance

Open HarryR opened this issue 5 years ago • 0 comments

There are a number of places where copy constructors are used that could significantly impact performance as the size of the circuit increases. Using constant references instead of passing by value in some specific places will help a lot.

For example, in libsnark::protoboard the following methods return values rather than references:

  • r1cs_variable_assignment<FieldT> full_variable_assignment() const;
  • r1cs_primary_input<FieldT> primary_input() const;
  • r1cs_auxiliary_input<FieldT> auxiliary_input() const;
  • r1cs_constraint_system<FieldT> get_constraint_system() const;

Making these return constant references will avoid copying a lot of data.

Making several class variables public will also solve this problem.

HarryR avatar Dec 05 '18 23:12 HarryR