Statically initialize constants #3
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently calling
Poseidon::new()loads the constants from scratch each time, converting them from string representation to field elements. There's ~1.8MB of constants, so this takes some time - tens of milliseconds in native and over 200ms in Wasm.However, this process really only needs to be done once, so we can statically initialize the constants and avoid paying this cost multiple times. This greatly speeds up signing PODs in
parcnet-pod:I've also added a second commit, which looks like a huge change but isn't that big: it breaks up the constants into separate crates, enabled by features, so that it's possible to include only those constants which are required. For example, PODs only require the poseidon-1, poseidon-2, and poseidon-5 constants, and the rest are dead weight. This cuts the WASM build for
parcnet-poddown from 1.7MB to 473KB. I do appreciate that this is a slightly scarier refactor, though, so we might want to discuss the implications.