-
Notifications
You must be signed in to change notification settings - Fork 359
Description
Description
Arkworks Prime fields are instantiated using procedural macros (e.g. #[derive(MontConfig)]
) that rely on the num_bigint::BigInt
library. While the flexibility of this approach allows for arbitrary-length prime moduli, it is slower than using system native arithmetic for small moduli.
To capture this optimization, in the linked PR we introduce a new procedural macro, SmallFp
, which targets primes < 128
bits. It generates field arithmetic using the smallest appropriate integer primitive (u8
, u16
, u32
, u64
, u128
).
For multiplication workloads, we observe a > 30% improvement across all primes < 2^127
bits. For Goldilocks specifically, we observe multiplication heavy performance within 5% of https://github.com/succinctlabs/plonky3/blob/main/goldilocks/src/lib.rs#L29 (in serial)
Note: We have prioritized correctness in this PR. We have not yet added prime-specific tricks or SIMD/vectorized optimizations. We will do this immediately upon acceptance of the linked PR.
TL;DR: SmallFp
is designed as a drop-in replacement for the existing prime field implementation whenever p < 128
bits. It also lays the groundwork for SIMD optimizations, which we plan to contribute next