Skip to content

Poseidon with inplace operations

Danny Willems requested to merge poseidon-with-inplace into master

Include !46 (merged)

Most of the arithmetic operations on the state in the implementation can be done in place, avoiding allocations. This is the goal of the second functor MakeInplace. Both implementations are provided as not every finite field implementation has inplace operators (yet).

I think it is possible to still decrease the number of values allocated, but it is a first improvement.

Here some benches, using the branch https://gitlab.com/dannywillems/ocaml-bls12-381/-/tree/do-not-use-ctypes for ocaml-bls12-381.

> dune exec ./benches/bench_poseidon252.exe     
Estimated testing time 30s (3 benchmarks x 10s). Change using '-quota'.
┌──────────────────────────────────────────────────────────────────────────────────────────┬──────────┬─────────┬──────────┬──────────┬────────────┐
│ Name                                                                                     │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├──────────────────────────────────────────────────────────────────────────────────────────┼──────────┼─────────┼──────────┼──────────┼────────────┤
│ Benchmark one permutation of Poseidon252 with ocaml-ff backend on an input of 5 elements │ 728.71us │ 98.74kw │   43.63w │   43.63w │    100.00% │
│ Benchmark one permutation of Poseidon252 with blst backend on an input of 5 elements     │ 315.40us │ 11.96kw │    6.27w │    6.27w │     43.28% │
│ Benchmark one permutation of Poseidon252 with blst backend and using inplace operations  │ 246.04us │  6.36kw │    3.45w │    3.45w │     33.76% │
│ on an input of 5 elements                                                                │          │         │          │          │            │
└──────────────────────────────────────────────────────────────────────────────────────────┴──────────┴─────────┴──────────┴──────────┴────────────┘
dune exec ./benches/bench_poseidon_orchard.exe
> Estimated testing time 30s (3 benchmarks x 10s). Change using '-quota'.
┌──────────────────────────────────────────────────────────────────────────────────────────┬──────────┬─────────┬──────────┬──────────┬────────────┐
│ Name                                                                                     │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├──────────────────────────────────────────────────────────────────────────────────────────┼──────────┼─────────┼──────────┼──────────┼────────────┤
│ Benchmark one permutation of Poseidon128 (Orchard parameters) with ocaml-ff backend on a │ 251.75us │ 40.21kw │   10.94w │   10.94w │    100.00% │
│ n input of 3 elements                                                                    │          │         │          │          │            │
│ Benchmark one permutation of Poseidon128 (Orchard parameters) with blst backend on an in │ 116.88us │  4.91kw │    1.56w │    1.56w │     46.43% │
│ put of 3 elements                                                                        │          │         │          │          │            │
│ Benchmark one permutation of Poseidon128 (Orchard parameters) with inplace operations an │  91.01us │  2.65kw │    0.89w │    0.89w │     36.15% │
│ d blst backend on an input of 3 elements                                                 │          │         │          │          │            │
└──────────────────────────────────────────────────────────────────────────────────────────┴──────────┴─────────┴──────────┴──────────┴────────────┘
Edited by Danny Willems

Merge request reports