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

chore(profiler): Use brillig names for outputted flamegraphs #7470

Merged
merged 9 commits into from
Feb 21, 2025

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Feb 20, 2025

Description

Problem*

No issue, just a QOL improvement I found while doing other documentation.

Summary*

We are using the brillig function index when writing a flamegraph file.
e.g. Running noir-profiler opcodes on this program:

fn main(ptr: pub u32, mut array: [u32; 5]) -> pub [u32; 5] {
    // Safety: Sets all elements after `ptr` in `array` to zero.
    let new_array = unsafe { write_to_array(ptr, array) };
    for i in 0..5 {
        if i > ptr {
            assert_eq(new_array[i], 0);
        } else {
            assert_eq(new_array[i], array[i]);
        }
    }
    new_array
}
unconstrained fn write_to_array(ptr: u32, mut array: [u32; 5]) -> [u32; 5] {
    for i in 0..5 {
        if i > ptr {
            array[i] = 0;
        }
    }
    array
}

Will result in the following flamegraph files: main_opcodes.svg, 0_brillig_opcodes.svg, 1_brillig_opcodes.svg, 2_brillig_opcodes.svg. The indices are pretty meaningless without a good amount extra context that is not reasonable to place on users.

Here is how the output directory looks after this PR:
Screenshot 2025-02-20 at 3 50 19 PM

I also changed the flamegraph title:
Screenshot 2025-02-20 at 3 51 24 PM

Before this PR the title would have just been ./target/program.json-brillig_0.

Additional Context

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@vezenovm vezenovm requested a review from a team February 20, 2025 20:52
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: d506839 Previous: 4e2cd60 Ratio
noir-lang_noir_json_parser_ 10 s 8 s 1.25

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@TomAFrench
Copy link
Member

How does this handle generic functions or functions with the same name in different modules?

@vezenovm
Copy link
Contributor Author

vezenovm commented Feb 20, 2025

How does this handle generic functions or functions with the same name in different modules?

This is going to override repeated names, however, this is already an issue with the ACIR flamegraph (although much more rare as it requires multiple ACIR functions) which uses the function name.

Similarly nargo info just repeats the name:
Screenshot 2025-02-20 at 4 18 59 PM

I'll look at a clean way of representing these function names, although we do lose a lot of the information by the time we get to Brillig/ACIR gen.

For now, I have just pushed a bit of a hack that checks for seen names and generates a suffix to attach to the previously seen function name.

Here is some example output:
Screenshot 2025-02-20 at 4 44 37 PM

EDIT: I also have modified the smoke test to check this functionality.

@jfecher
Copy link
Contributor

jfecher commented Feb 21, 2025

For now, I have just pushed a bit of a hack that checks for seen names and generates a suffix to attach to the previously seen function name.

Do we check if the suffix already exists as well? E.g. if we not only have two duplicate write_to_array functions, but also have a write_to_array1 function defined?

KOL improvement

Koality of life? 🐨

@vezenovm
Copy link
Contributor Author

Do we check if the suffix already exists as well? E.g. if we not only have two duplicate write_to_array functions, but also have a write_to_array1 function defined?

The hack tracks a map of seen names -> suffixes. So it will see multiple duplicates and apply the appropriate suffix. Another example where I use a third duplicate write_to_array:
Screenshot 2025-02-21 at 10 17 25 AM

Koality of life? 🐨

🤣 I was definitely typing too fast. Edited the description

@jfecher
Copy link
Contributor

jfecher commented Feb 21, 2025

Another example where I use a third duplicate write_to_array:

I don't mean a third duplicate, I mean still two write_to_array and one function called in source as write_to_array_1 already such that it collides with the default disambiguation strategy. This can potentially happen N times

@vezenovm
Copy link
Contributor Author

I don't mean a third duplicate, I mean still two write_to_array and one function called in source as write_to_array_1 already such that it collides with the default disambiguation strategy. This can potentially happen N times

Ah I see I read that wrong. Yeah good call out. I'll modify to cover that case.

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The while loop could conceptually slow down code but only on inputs where users would go out of their way to name most functions with a numbering scheme. That shouldn't happen in practice so this is fine for a quick tooling feature.

@vezenovm
Copy link
Contributor Author

LGTM. The while loop could conceptually slow down code but only on inputs where users would go out of their way to name most functions with a numbering scheme. That shouldn't happen in practice so this is fine for a quick tooling feature.

Yeah I figured this case would be quite rare.

@vezenovm
Copy link
Contributor Author

I switched to the strategy laid out here #7470 (comment).

I was originally trying to recompute a unique index in the profiler. This is unnecessary as a unique index has already been computed for us.

@vezenovm vezenovm requested a review from jfecher February 21, 2025 16:47
@vezenovm vezenovm changed the title chore(profile): Use brillig names for outputted flamegraphs chore(profiler): Use brillig names for outputted flamegraphs Feb 21, 2025
@vezenovm vezenovm enabled auto-merge February 21, 2025 16:50
@vezenovm vezenovm added this pull request to the merge queue Feb 21, 2025
Merged via the queue into master with commit f442c31 Feb 21, 2025
102 checks passed
@vezenovm vezenovm deleted the mv/use-brillig-names-in-flamegraph-output branch February 21, 2025 17:19
TomAFrench added a commit that referenced this pull request Feb 25, 2025
* master: (74 commits)
  feat: optimize out range checks on limiting cases (#7510)
  chore: clippy fixes (#7505)
  chore(docs): Supplement docs on `modexp` as a required precompile for Barretenberg's Solidity verifier (#7508)
  feat(debugger): REPL add breakpoint by sourcecode line (#5204)
  fix: issue duplicate error on impl function without self (#7490)
  feat(experimental): Support struct constructors in match patterns (#7489)
  feat: use resolved type instead of needing Constructor.struct_type (#7500)
  feat: better error message when keyword is found instead of type in p… (#7501)
  chore: bump external pinned commits (#7497)
  feat(experimental): Add invalid pattern syntax error (#7487)
  fix(performance): Accurately mark safe constant indices for arrays of complex types (#7491)
  fix(experimental): Allow shadowing in match patterns (#7484)
  chore: regression test #7195 (#7233)
  chore(docs): Section on `noir-profiler execution-opcodes` (#7480)
  chore: improve proptesting of 128bit values in `noirc_abi` (#7485)
  chore(profiler): Use brillig names for outputted flamegraphs  (#7470)
  chore(docs): Profiler images reference (#7481)
  fix: don't use dummy location when inserting debug code (#7482)
  feat(cli)!: Add `--unstable-features` to gate unstable features (#7449)
  feat: Sync from aztec-packages (#7474)
  ...
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Feb 26, 2025
feat: let all compiler errors carry a Location instead of a Span (noir-lang/noir#7486)
chore: Increaes base64's allotted time (noir-lang/noir#7521)
fix: don't crash on broken impl syntax (noir-lang/noir#7512)
feat: optimize out range checks on limiting cases (noir-lang/noir#7510)
chore: clippy fixes (noir-lang/noir#7505)
chore(docs): Supplement docs on `modexp` as a required precompile for Barretenberg's Solidity verifier (noir-lang/noir#7508)
feat(debugger): REPL add breakpoint by sourcecode line (noir-lang/noir#5204)
fix: issue duplicate error on impl function without self (noir-lang/noir#7490)
feat(experimental): Support struct constructors in match patterns (noir-lang/noir#7489)
feat: use resolved type instead of needing Constructor.struct_type (noir-lang/noir#7500)
feat: better error message when keyword is found instead of type in p… (noir-lang/noir#7501)
chore: bump external pinned commits (noir-lang/noir#7497)
feat(experimental): Add invalid pattern syntax error (noir-lang/noir#7487)
fix(performance): Accurately mark safe constant indices for arrays of complex types (noir-lang/noir#7491)
fix(experimental): Allow shadowing in match patterns (noir-lang/noir#7484)
chore: regression test #7195 (noir-lang/noir#7233)
chore(docs): Section on `noir-profiler execution-opcodes` (noir-lang/noir#7480)
chore: improve proptesting of 128bit values in `noirc_abi` (noir-lang/noir#7485)
chore(profiler): Use brillig names for outputted flamegraphs  (noir-lang/noir#7470)
chore(docs): Profiler images reference (noir-lang/noir#7481)
fix: don't use dummy location when inserting debug code (noir-lang/noir#7482)
feat(cli)!: Add `--unstable-features` to gate unstable features (noir-lang/noir#7449)
TomAFrench pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Feb 26, 2025
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: bump external pinned commits
(noir-lang/noir#7515)
feat: let all compiler errors carry a Location instead of a Span
(noir-lang/noir#7486)
chore: Increaes base64's allotted time
(noir-lang/noir#7521)
fix: don't crash on broken impl syntax
(noir-lang/noir#7512)
feat: optimize out range checks on limiting cases
(noir-lang/noir#7510)
chore: clippy fixes (noir-lang/noir#7505)
chore(docs): Supplement docs on `modexp` as a required precompile for
Barretenberg's Solidity verifier
(noir-lang/noir#7508)
feat(debugger): REPL add breakpoint by sourcecode line
(noir-lang/noir#5204)
fix: issue duplicate error on impl function without self
(noir-lang/noir#7490)
feat(experimental): Support struct constructors in match patterns
(noir-lang/noir#7489)
feat: use resolved type instead of needing Constructor.struct_type
(noir-lang/noir#7500)
feat: better error message when keyword is found instead of type in p…
(noir-lang/noir#7501)
chore: bump external pinned commits
(noir-lang/noir#7497)
feat(experimental): Add invalid pattern syntax error
(noir-lang/noir#7487)
fix(performance): Accurately mark safe constant indices for arrays of
complex types (noir-lang/noir#7491)
fix(experimental): Allow shadowing in match patterns
(noir-lang/noir#7484)
chore: regression test #7195
(noir-lang/noir#7233)
chore(docs): Section on `noir-profiler execution-opcodes`
(noir-lang/noir#7480)
chore: improve proptesting of 128bit values in `noirc_abi`
(noir-lang/noir#7485)
chore(profiler): Use brillig names for outputted flamegraphs
(noir-lang/noir#7470)
chore(docs): Profiler images reference
(noir-lang/noir#7481)
fix: don't use dummy location when inserting debug code
(noir-lang/noir#7482)
feat(cli)!: Add `--unstable-features` to gate unstable features
(noir-lang/noir#7449)
END_COMMIT_OVERRIDE

---------

Co-authored-by: guipublic <guipublic@gmail.com>
Co-authored-by: guipublic <47281315+guipublic@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants