Advaita Saha

TECH

Benchmarking & Optimizations - Banderwagon Implementation

epf

So this week was all about testing & discussing about possible optimizations for the Banderwagon implementation. I have also been working on the integration of the of Constantine library into nim-eth-verkle. Now this led to a long discussion with the Nimbus team, and we have decided to go with the following approach:

  • Start with a PoC as Constantine as a git submodule.
  • Then later we will collaborate with the Codex team to make a nimble install for the Constantine repository.

Also made another PR for the batch operations for MapToScalarField, which I missed initially and was a dependency for @agnish

Now let’s get into the benchmarks. It turns out that our implementation is faster in few cases, while being a bit slower in other cases.

Benchmarks ( in Apple Silicon M1 Chip )

Constantine Bechnmarks :- constatine-benchmarks

go-ipa Benchmarks :- go-ipa-benchmarks

Conclusions ( from tests in Apple Silicon M1 Chip )

Benchmark OperationConstantine Implgo-ipa ImplRemarks
Equality Check58 ns/op48 ns/opslightly slower ✅
Subgroup Check2932 ns/op8819 ns/ophighly faster 🚀
Serialization1978 ns/op1843 ns/opslightly slower ✅
Deserialization32530 ns/op11175 ns/ophighly slower ❌
BatchSerialization197112 ns/op184184 ns/opslightly slower ✅

What’s the problem with Deserialization?

After searching about this a lot & studying my and the go-ipa implementation & I realized that the problem lies in performing the square root of a field element. In constantine I was using the Tonelli-Shanks Algorithm which is becoming a bottleneck. Now this algorithm have been optimized in the go-ipa, which doesn not exist in the constatine library.

After discussing with @mratsim & @ignacio I found out this can be optimized using the dlog precompute table, over the Tonelli-Shanks Algorithm. To read more about this, I highly recommend reading through the blog post by @ignacio Tonelli-Shanks with PreComputed dlog tables

Upcoming

  • Meeting with the Codex team for discussion regarding future of constantine, for nimp2p lib
  • Working on the integration of constantine into nim-eth-verkle, meeting with danille & agnish
  • Assist Agnish on finishing the ipa implementation