-
Notifications
You must be signed in to change notification settings - Fork 212
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
Small Vec Linear Combinations #336
Comments
A separate proposal would be to avoid the generation of too many symbolic LC. Currently, each AllocatedFp is associated with a Variable in the constraint system. Thus, mul_by_constant and add would all create a new symbolic LC. One potential direction is to let AllocatedFp uses a linear combination of variables instead of a symbolic LC, if it is optimized for the number of constraints. |
I think this is a great idea. The alternative idea I was thinking of was to introduce drop semantics to variables, but that was growing in complexity very rapidly. (We may still need something of that form to remove symbolic LC's that are intermediate computation steps though, in the case of density optimizations) |
One way to do this is to change the pub enum Variable<F> {
/// Represents the "zero" constant.
Zero,
/// Represents of the "one" constant.
One,
/// Represents a public instance variable.
Instance(usize),
/// Represents a private witness variable.
Witness(usize),
/// Represents of a linear combination.
SymbolicLc(InlineOrIndex<F>),
}
// Needed if we want to make this an implementation detail.
pub struct InlineOrIndex<F>(InlineOrIndexInner<F>);
enum InlineOrIndexInner<F> {
Index(usize),
Lc(StackVec<(F, Variable<F>)>), // Not sure if this needs to be `Box`
} The downside of this approach is that |
Separately, one might want to reduce the memory consumption of Along with coefficient-interning (#122), this could lead to a significant memory improvement. |
I feel like we will need to eventually remove
Its not clear to me that that is going to be reducing memory under the inline or index API. Symbolic LC could still be storing an In the case where it doesn't have I think changing |
You're right, that optimization is not useful. Separately, to compress the size for
The reason I wanted to put this in |
In the case of density optimizations, I think we want to keep building it up in An alternative to that is that we introduce |
Copying over from another issue: I think there are two approaches:
Separately, it would also be worthwhile to consider what can be done for density optimizations; the foregoing mostly only makes sense when optimizing for constraints. |
Every variable is eventually dropped, so we can't necessarily prune, if we want to have the "outlining" optimization available to use. |
Err |
Summary
As currently written, a symbolic LC is created on every operation. We should expect that most Symbolic LC's are small, and probably should try to keep things on stack via small vec optimizations, perhaps using https://github.com/servo/rust-smallvec.
We definitely shouldn't switch without a more detailed benchmark suite (getting average symbolic LC size, seeing how much of the time is spent in mallocs, seeing if things actually get faster etc.)
For Admin Use
The text was updated successfully, but these errors were encountered: