-
Notifications
You must be signed in to change notification settings - Fork 121
Use an array instead of a Vec #3126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
poseidon/src/poseidon.rs
Outdated
#[serde_as(as = "Vec<Vec<o1_utils::serialization::SerdeAs>>")] | ||
pub mds: Vec<Vec<F>>, | ||
#[serde_as(as = "Vec<[o1_utils::serialization::SerdeAs; 3]>")] | ||
pub mds: Vec<[F; 3]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What serializer(s) are we using here and what are the backward compatibility requirements? It's possible that we would prefer to serialize as &[F]
instead of [F; 3]
to maintain backward compatibility (arrays aren't generally serialized with a length). .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would probably break compatibility on the serialization level.
However, if the performance is non-negligible, I would be in favor of doing it.
Note that other optimisations can be done at the same time (see below for the contiguous allocated memory or see discussions on Slack to move to Poseidon2 or a Poseidon instance with full/partial rounds), and there is a balance to discuss regarding how/if it would impact the Mina codebase (for instance by requiring a HF).
@@ -9,7 +9,7 @@ use std::str::FromStr; | |||
fn params() -> ArithmeticSpongeParams<Fp> { | |||
ArithmeticSpongeParams { | |||
mds: vec![ | |||
vec![ | |||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any .sage
files that need a similar update?
I like the idea. A further optimisation is to get a single contiguous piece of memory that contains:
|
9d5d9c0
to
6c33af5
Compare
@dannywillems, there are a lot of round-constants. It's generally not advisable to make stack values that large. I'm not sure I want to make that change (I just needed the inner values of
|
It would also probably make sense to lazily initialize these as |
6c33af5
to
e7807b8
Compare
The
Vec
was always had the same length. There's no reason to use aVec
here, unless I'm missing something