Skip to content

Add a debug option to generate a flamegraph for compiler performance #4075

@carolynzech

Description

@carolynzech

Proposed change: For a given code generation pass, we'd get the call tree annotated with the time spent in each function. For instance, if codegen_items calls codegen_function, which calls codegen_statement n times, etc., we'd get the time we spent in each of those calls, down to the end of the call tree. I'm imagining we'd visualize it as a tree because the depth of the call stack is also important, but I'm flexible on the format; the main point is getting data on how long different parts of codegen take, not just codegen as a whole.

Motivation: From some rudimentary benchmarking with with_timer:

/// Execute the provided function and measure the clock time it took for its execution.
/// Log the time with the given description.
pub fn with_timer<T, F>(func: F, description: &str) -> T

we've determined that most of Kani's compiler runtime comes from code generation. But we need more fine-grained data to know why code generation is slow. Currently, it's unclear whether:

  • Most functions are fast enough, but there are specific outliers we can blame, e.g., if codegening a function with fat pointers or dynamic dispatch is much slower than codegening functions without, or
  • Most functions are fast enough in isolation, but we have a deep call tree so their cumulative time is slow, suggesting that we need a larger-scale refactoring to produce speedups, or at least small-scale optimizations of multiple functions.

Having this data would help us make that determination.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [C] InternalTracks some internal work. I.e.: Users should not be affected.[E] PerformanceTrack performance improvement (Time / Memory / CPU)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions