Skip to content
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

Calls to constrained functions in an unconstrained context are needlessly inefficient #91

Open
TomAFrench opened this issue Jan 6, 2025 · 0 comments · May be fixed by #102
Open

Calls to constrained functions in an unconstrained context are needlessly inefficient #91

TomAFrench opened this issue Jan 6, 2025 · 0 comments · May be fixed by #102
Assignees
Labels
enhancement New feature or request

Comments

@TomAFrench
Copy link
Member

See the mul function below which calls the unconstrained variant and then constrains it using evaluation_quadratic_expression:

pub(crate) fn mul<let N: u32, let MOD_BITS: u32>(
params: P<N, MOD_BITS>,
lhs: [Field; N],
rhs: [Field; N],
) -> [Field; N] {
let result = unsafe { __mul::<_, MOD_BITS>(params, lhs, rhs) };
evaluate_quadratic_expression(
params,
[[lhs]],
[[false]],
[[rhs]],
[[false]],
[result],
[true],
);
result
}

If this mul function is called from an unconstrained context then we need to execute both the __mul function and the evaluation_quadratic_expression which is pointless in an unconstrained context and needlessly slows down execution. We can avoid the need for this by conditioning the evaluation_quadratic_expression on !std::runtime::is_unconstrained() so this only happens in constrained code.

@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jan 6, 2025
@Savio-Sou Savio-Sou added the enhancement New feature or request label Jan 15, 2025
@olehmisar olehmisar linked a pull request Jan 20, 2025 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

3 participants