clearmatics / libff

C++ library for Finite Fields and Elliptic Curves (forked from scipr-lab/libff)

Home Page:https://clearmatics.github.io/libff/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

More static / compile-time constants

dtebbs opened this issue · comments

(Similar theme to #36)
There seems to be an opportunity to pre-compute many constants (e.g. https://github.com/clearmatics/libff/blob/master/libff/algebra/fields/fp.tcc#L285 which is used a lot in gadgets and runtime computation).

It could be worth including static_initialize methods on more field and group objects, to pre-compute these values which can be computed in a generic way.

Some early perf data. Statically initializing Fp::one() and Fp::zero() in alt_bn128.
Gave the following perf changes for the simple group profile app (read perf is particularly affected, since it perpetually assigns Fq::one to the Z component). I'd expect there are a lot of places that this will impact so some degree.

The zeth prover_test also runs a few seconds faster on my machine (although that's not necessarily the best way to profile - just as an anecdote).

G1 ADD:
BEFORE:

(leave) group add operation profiling           [0.7200s x1.00] (265368.8234s x0.00 from start)
(leave) group add operation profiling           [0.7226s x1.00] (265375.2738s x0.00 from start)
(leave) group add operation profiling           [0.7113s x1.00] (265381.8299s x0.00 from start)

AFTER:

(leave) group add operation profiling           [0.7171s x0.99] (265189.2317s x0.00 from start)
(leave) group add operation profiling           [0.7089s x1.00] (265196.6813s x0.00 from start)
(leave) group add operation profiling           [0.7019s x1.00] (265203.4976s x0.00 from start)

G2 ADD:
BEFORE:

(leave) group add operation profiling           [3.3668s x1.00] (265373.1002s x0.00 from start)
(leave) group add operation profiling           [3.3335s x1.00] (265379.5098s x0.00 from start)
(leave) group add operation profiling           [3.3199s x1.00] (265386.0634s x0.00 from start)

AFTER:

(leave) group add operation profiling           [3.3150s x1.00] (265193.4507s x0.00 from start)
(leave) group add operation profiling           [3.3352s x1.00] (265200.9204s x0.00 from start)
(leave) group add operation profiling           [3.4241s x0.99] (265207.8661s x0.00 from start)

G1 READ:
BEFORE:

(leave) Read group elements profiling           [0.0530s x1.00] (265447.1996s x0.00 from start)
(leave) Read group elements profiling           [0.0668s x0.98] (265449.6453s x0.00 from start)
(leave) Read group elements profiling           [0.0574s x0.99] (265451.7475s x0.00 from start)

AFTER:

(leave) Read group elements profiling           [0.0484s x0.88] (265248.9902s x0.00 from start)
(leave) Read group elements profiling           [0.0494s x0.99] (265257.4390s x0.00 from start)
(leave) Read group elements profiling           [0.0410s x0.99] (265260.4630s x0.00 from start)

G2 READ:
BEFORE:

(leave) Read group elements profiling           [0.0946s x0.99] (265447.2944s x0.00 from start)
(leave) Read group elements profiling           [0.0949s x0.99] (265449.7404s x0.00 from start)
(leave) Read group elements profiling           [0.0940s x0.99] (265451.8418s x0.00 from start)

AFTER:

(leave) Read group elements profiling           [0.0992s x0.91] (265249.0896s x0.00 from start)
(leave) Read group elements profiling           [0.0713s x0.99] (265257.5110s x0.00 from start)
(leave) Read group elements profiling           [0.0730s x0.99] (265260.5364s x0.00 from start)

Partially addressed by #40