See:
There are optimisations which can be made which reduce the necessary amount of in-memory data required for the proving key.
- Don't use Jacobian coordinates for the proving key while it's in-memory (removes the X coord), allocate X coord on stack when performing calculation
- Use a directly accessible format which allows the proving key to be
mmap'd and let the kernel figure it out.
- Anything which is used independently and sequentially means the rest can be discarded:
The proving key consists of five parts - PK_A, PK_B, PK_C, PK_K, PK_H which are used independently and sequentially.
Load each one at a time, rather than all of them.
Either way, need to create a benchmark for prove which tracks the peak memory usage.
Any changes should avoid modifying libsnark directly, we still want to use it as a submodule.
With the mmap approach, if the offsets & sizes of sections for A, B, C, K and H are known ahead of time, then madvise can be used depending on the access pattern. If it's purely sequential then MADV_SEQUENTIAL can be used, however if it's at random then doing a pre-emptive sequential read into memory will offer a performance improvement.
Either way - disk reads vs memory usage trade-off again.