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

Frontend is slower than necessary #791

Closed
jfecher opened this issue Feb 9, 2023 · 4 comments · Fixed by #869
Closed

Frontend is slower than necessary #791

jfecher opened this issue Feb 9, 2023 · 4 comments · Fixed by #869
Labels
bug Something isn't working

Comments

@jfecher
Copy link
Contributor

jfecher commented Feb 9, 2023

Description

Aim

Trying to run nargo test on a reasonably small code sample with 4 tests.

Expected behavior

The frontend should finish checking the code quickly and the backend should take a majority of the time as it goes through each test individually.

Bug

Instead, the frontend takes a relatively consistent ~2 seconds on my machine (Macbook M1 Pro) despite the small source code size. We should investigate the reason(s) for this and fix them since the front end of a compiler should be able to achieve ~100k lines of code per second for a similar feature set to noir (citation needed). It is unclear how much of these 2 seconds are startup time or time that would scale with program size.

@jfecher jfecher added the bug Something isn't working label Feb 9, 2023
@jfecher
Copy link
Contributor Author

jfecher commented Feb 10, 2023

Some preliminary testing reveals the source of the slowness is almost entirely within collect_defs and not the subsequent resolution steps or type checking, nor the steps of adding the stdlib beforehand.

@jfecher
Copy link
Contributor Author

jfecher commented Feb 15, 2023

Here's a flamegraph of nargo prove p running on a short program. You can see that almost the entire middle plateau is from collect_defs. Further inspection then reveals that the majority of the time within collect_defs is actually spent during parsing. A bit above half of this time is spent in expression_with_precedence, and a bit below half seems to be spent in Drop::drop for parser errors. The former can be fixed with a more efficient parser, but the later may be more inherent to chumsky. We may have to wait for an update in chumsky to fix the drop performance impact, or change our parsing library.

image

This was referenced Feb 15, 2023
@jfecher
Copy link
Contributor Author

jfecher commented Feb 17, 2023

New flamegraph after the optimization in #869:
image

Now only the middle tower is the parsing-related portion. Our runtime is now dominated by calls to common::crs::read_crs for short programs at least.

@jfecher
Copy link
Contributor Author

jfecher commented Feb 17, 2023

Just for completeness, here is a flamegraph of nargo prove p running on a somewhat larger program (8_integration):
image

Here our runtime is dominated almost entirely by barretenberg. All the little hills that can be seen are from barretenberg::scalar_multiplication::reduce_buckets. The taller spike on the right is from prove_cmd::run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant