HarryR / ethsnarks

A toolkit for viable zk-SNARKS on Ethereum, Web, Mobile and Desktop
GNU Lesser General Public License v3.0
240 stars 57 forks source link

Reduce build times #25

Closed HarryR closed 5 years ago

HarryR commented 6 years ago

Now the project is taking about 10 minutes to build, most of this time is due to the tests and compiling all of the templates again and again for each test binary. There must be a way to reduce the build time.

I suggest:

Hopefully that should reduce the amount of unnecessary duplicate compilations.

Need to create header files for the common code, then create an OBJECT library with the common code. Then create an object library for miximus and hashpreimage. Then make everything link against the object and static libraries.

The combination of using header files, linking against object libraries etc. will reduce the number of times each file is compiled, hopefully to only 1, aside from where templates are needed - then those should be split into .tcc files.

HarryR commented 5 years ago

Unfortunately I can only see build times increasing without splitting the project into separate modules.

These modules would likely be:

Then the parent repositories:

The problem is the ethsnarks-cxx repository can't be built standalone, and I'm wary of it becoming difficult to do work across multiple languages in the same repository...

Another problem is that the integration tests would need to happen in the ethsnarks repository, which would likely keep the build time for that repository quite high.

But it would allow the ethsnarks-cxx repository to be included by other projects which have their own libsnark dependency and build system.

This is somewhat related to #13

HarryR commented 5 years ago

I'm working on a branch which reduces the number of files that need to be compiled:

This builds many of the utilities under emscripten, and also runs into the same error, whenever we output GMP values:

../libff.a(alt_bn128_g1.cpp.o): In function `std::ostream& libff::operator<< <4l>(std::ostream&, libff::bigint<4l> const&)':
alt_bn128_g1.cpp:(.text._ZN5libfflsILl4EEERSoS1_RKNS_6bigintIXT_EEE[_ZN5libfflsILl4EEERSoS1_RKNS_6bigintIXT_EEE]+0x3e): undefined reference to `operator<<(std::ostream&, __mpz_struct const*)'

The good news is that build times are significantly reduced :D It also solves the problem of duplicate compile flags being added by the two levels of libraries below (which each pretend like their high-level libraries, and add lots of compile flags again).

Now the C++ builds a lot quicker.