feat: compiler-phase timing flamegraphs from tracing spans - #13300
Draft
TomAFrench wants to merge 3 commits into
Draft
feat: compiler-phase timing flamegraphs from tracing spans#13300TomAFrench wants to merge 3 commits into
TomAFrench wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
We have no easy way to see where
nargo compilespends its time. The compiler already emitstracingspans as JSON logs (viaNARGO_LOG_DIR+NOIR_LOG), but nothing consumes them, and some key phases (individual SSA passes, parsing) had no spans at all.Summary
Adds a compiler-phase profiling workflow:
produces, from the span logs of a single
nargo compilerun:compiler-flamegraph.svg— an aggregated, self-time-weighted flamegraph of compiler phases (inferno).compiler-trace.json— a per-invocation timeline that opens in Perfetto.Changes:
ssa_pass{pass=...}span around every SSA pass inSsaBuilder::try_run_pass, and a span onparse_program(lexing is lazily interleaved with parsing, so there is a single combined span).tooling/compiler_profiler(noir-compiler-profiler), that streams the JSON span logs, reconstructs the call tree from close events (which carry the authoritative ancestor chain plustime.busy/time.idle), and emits both artifacts. It is deliberately not part of the user-facingnoir-profiler, which profiles Noir programs rather than the compiler.(self)frame, wall-clock time outside any root span as(untracked), and the tool reports what fraction of wall clock the flamegraph accounts for, warning on anomalies (unclosed spans, children exceeding their parent).compile_programitself) appear as detached roots in tracing; they are re-parented by time containment.just profile-compilerrecipe +tooling/compiler_profiler/README.mddocumenting usage, span filters, and how to read the output.Per-pass durations in the flamegraph match
nargo compile --benchmark-codegento the millisecond across all 74 pipeline steps.The default span filter (
trace,noirc_frontend::elaborator=info) keeps logs small and timings accurate; fullNOIR_LOG=traceadditionally captures the elaborator's per-expression spans for a deep frontend breakdown at the cost of multi-GB logs and significant observer distortion.Additional Context
The flamegraph for
semaphore_depth_10(~2.2s cold compile) breaks down as: ~0.4s parallel parsing, ~0.6s check/elaboration, ~1.1s SSA passes + ACIR gen, ~40ms monomorphization.Documentation
Check one:
PR Checklist
cargo fmton default settings.