Skip to content

Commit 06f477f

Browse files
committed
update beta.3 docs
1 parent 0d8ae34 commit 06f477f

File tree

1 file changed

+20
-32
lines changed
  • docs/versioned_docs/version-v1.0.0-beta.3/tooling

1 file changed

+20
-32
lines changed

docs/versioned_docs/version-v1.0.0-beta.3/tooling/profiler.md

+20-32
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
title: Noir Profiler
3-
description: Learn about the Noir Profiler, how to generate execution flamegraphs, identify bottlenecks, and visualize optimizations.
4-
keywords: [profiling, profiler, flamegraph]
3+
description: Learn about the Noir Profiler, how to generate execution flamegraphs, identify bottlenecks, and visualize optimizations.
4+
keywords: [profiling, profiler, flamegraph]
55
sidebar_position: 0
66
---
77

88
## Noir Profiler
99

10-
`noir-profiler` is a sampling profiler designed to analyze and visualize Noir programs. It assists developers to identify bottlenecks by mapping execution data back to the original source code.
10+
`noir-profiler` is a sampling profiler designed to analyze and visualize Noir programs. It assists developers to identify bottlenecks by mapping execution data back to the original source code.
1111

1212
### Installation
1313

14-
`noir-profiler` comes out of the box with [noirup](../getting_started/noir_installation.md). Test that you have the profiler installed by running `noir-profiler --version`.
14+
`noir-profiler` comes out of the box with [noirup](../getting_started/noir_installation.md). Test that you have the profiler installed by running `noir-profiler --version`.
1515

1616
### Usage
1717

@@ -33,20 +33,18 @@ ptr = 1
3333
array = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
3434
```
3535

36-
Running `nargo info` we can get some information about the opcodes produced by this program, but it doesn't give us a lot of info on its own. Compile and execute this program normally using `nargo compile` and `nargo execute`.
36+
Running `nargo info` we can get some information about the opcodes produced by this program, but it doesn't give us a lot of info on its own. Compile and execute this program normally using `nargo compile` and `nargo execute`.
3737

3838
### Generating an ACIR opcode flamegraph
3939

40-
The program on its own is quite high-level. Let's get a more granular look at what is happening by using `noir-profiler`.
40+
The program on its own is quite high-level. Let's get a more granular look at what is happening by using `noir-profiler`.
4141

4242
After compiling the program, run the following:
4343
```sh
44-
noir-profiler opcodes --artifact-path ./target/program.json -output ./target/
44+
noir-profiler opcodes --artifact-path ./target/program.json --output ./target/
4545
```
4646
Below you can see an example flamegraph with a total 387 opcodes (using `nargo` version 1.0.0-beta.2):
47-
<picture>
48-
<img src="../../static/img/tooling/profiler/acir-flamegraph-unoptimized.png">
49-
</picture>
47+
![ACIR Flamegraph Unoptimized](@site/static/img/tooling/profiler/acir-flamegraph-unoptimized.png)
5048

5149
You should now have a flamegraph that maps ACIR opcodes to their corresponding locations in the source code. We strongly recommend generating these graphs yourself as you follow this guide. Opening the flamegraph in a browser provides a more interactive experience, allowing you to click into and examine different regions of the graph. Simply viewing the image file won't offer the same level of insight.
5250

@@ -83,45 +81,35 @@ unconstrained fn zero_out_array(ptr: u32, mut array: [u32; 32]) -> [u32; 32] {
8381
We chose to instead write our array inside of the unconstrained function. Then inside of our circuit we assert on every value in the array returned from the unconstrained function.
8482

8583
This new program produces the following ACIR opcodes flamegraph with a total of 284 opcodes:
86-
<picture>
87-
<img src="../../static/img/tooling/profiler/acir-flamegraph-optimized.png">
88-
</picture>
84+
![ACIR Flamegraph Optimized](@site/static/img/tooling/profiler/acir-flamegraph-optimized.png)
8985

90-
In the above image we searched for the ACIR opcodes due to `i > ptr` in the source code. Trigger a search by clicking on "Search" in the top right corner of the flamegraph. In the bottom right corner of the image above, you will note that the flamegraph displays the percentage of all opcodes associated with that search. Searching for `memory::op` in the optimized flamegraph will result in no matches. This is due to no longer using a dynamic array in our circuit. By dynamic array, we are referring to using a dynamic index (values reliant upon witness inputs) when working with arrays. Most of the memory operations, have now been replaced with arithmetic operations as we are reading two arrays from known constant indices.
86+
In the above image we searched for the ACIR opcodes due to `i > ptr` in the source code. Trigger a search by clicking on "Search" in the top right corner of the flamegraph. In the bottom right corner of the image above, you will note that the flamegraph displays the percentage of all opcodes associated with that search. Searching for `memory::op` in the optimized flamegraph will result in no matches. This is due to no longer using a dynamic array in our circuit. By dynamic array, we are referring to using a dynamic index (values reliant upon witness inputs) when working with arrays. Most of the memory operations, have now been replaced with arithmetic operations as we are reading two arrays from known constant indices.
9187

9288
### Generate a backend gates flamegraph
9389

94-
Unfortunately, ACIR opcodes do not give us a full picture of where the cost of this program lies.
95-
The `gates` command also accepts a backend binary. In the [quick start guide](../getting_started/quick_start.md#proving-backend) you can see how to get started with the [Barretenberg proving backend](https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg).
90+
Unfortunately, ACIR opcodes do not give us a full picture of where the cost of this program lies.
91+
The `gates` command also accepts a backend binary. In the [quick start guide](../getting_started/quick_start.md#proving-backend) you can see how to get started with the [Barretenberg proving backend](https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg).
9692

9793
Run the following command:
9894
```sh
9995
noir-profiler gates --artifact-path ./target/program.json --backend-path bb --output ./target
10096
```
101-
`--backend-path` accepts a path to the backend binary. In the above command we assume that you have the backend binary path saved in your PATH. If you do not, you will have to pass the binary's absolute path.
97+
`--backend-path` accepts a path to the backend binary. In the above command we assume that you have the backend binary path saved in your PATH. If you do not, you will have to pass the binary's absolute path.
10298

10399
This produces the following flamegraph with 3,737 total backend gates (using `bb` version 0.76.4):
104-
<picture>
105-
<img src="../../static/img/tooling/profiler/gates-flamegraph-unoptimized.png">
106-
</picture>
100+
![Gates Flamegraph Unoptimized](@site/static/img/tooling/profiler/gates-flamegraph-unoptimized.png)
107101

108102
Searching for ACIR `memory::op` opcodes, they look to cause about 18.2% of the backend gates.
109103

110-
You will notice that the majority of the backend gates come from the ACIR range opcodes. This is due to the way UltraHonk handles range constraints, which is the backend used in this example. UltraHonk uses lookup tables internally for its range gates. These can take up the majority of the gates for a small circuit, but whose impact becomes more meaningful in larger circuits. If our array was much larger, range gates would become a much smaller percentage of our total circuit.
104+
You will notice that the majority of the backend gates come from the ACIR range opcodes. This is due to the way UltraHonk handles range constraints, which is the backend used in this example. UltraHonk uses lookup tables internally for its range gates. These can take up the majority of the gates for a small circuit, but whose impact becomes more meaningful in larger circuits. If our array was much larger, range gates would become a much smaller percentage of our total circuit.
111105
Here is an example backend gates flamegraph for the same program in this guide but with an array of size 2048:
112-
<picture>
113-
<img src="../../static/img/tooling/profiler/gates-flamegraph-unoptimized-2048.png">
114-
</picture>
115-
Every backend implements ACIR opcodes differently, so it is important to profile both the ACIR and the backend gates to get a full picture.
106+
![Gates Flamegraph Unoptimized 2048](@site/static/img/tooling/profiler/gates-flamegraph-unoptimized-2048.png)
107+
Every backend implements ACIR opcodes differently, so it is important to profile both the ACIR and the backend gates to get a full picture.
116108

117109
Now let's generate a graph for our optimized circuit with an array of size 32. We get the following flamegraph that produces 3,062 total backend gates:
118-
<picture>
119-
<img src="../../static/img/tooling/profiler/gates-flamegraph-optimized.png">
120-
</picture>
110+
![Gates Flamegraph Optimized](@site/static/img/tooling/profiler/gates-flamegraph-optimized.png)
121111

122-
In the optimized flamegraph, we searched for the backend gates due to `i > ptr` in the source code. The backend gates associated with this call stack were only 3.8% of the total backend gates. If we look back to the ACIR flamegraph, that same code was the cause of 43.3% ACIR opcodes. This discrepancy reiterates the earlier point about profiling both the ACIR opcodes and backend gates.
112+
In the optimized flamegraph, we searched for the backend gates due to `i > ptr` in the source code. The backend gates associated with this call stack were only 3.8% of the total backend gates. If we look back to the ACIR flamegraph, that same code was the cause of 43.3% ACIR opcodes. This discrepancy reiterates the earlier point about profiling both the ACIR opcodes and backend gates.
123113

124114
For posterity, here is the flamegraph for the same program with a size 2048 array:
125-
<picture>
126-
<img src="../../static/img/tooling/profiler/gates-flamegraph-optimized-2048.png">
127-
</picture>
115+
![Gates Flamegraph Optimized 2048](@site/static/img/tooling/profiler/gates-flamegraph-optimized-2048.png)

0 commit comments

Comments
 (0)