Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented May 28, 2025

Normally, we don't instrument single-edge methods, it means if such a method is an inline root (it happens in Micro-benchmarks as normally single-edge methods are inlined somewhere), all callees don't receive an inlining boost.

@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 02:15
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 28, 2025
Copilot

This comment was marked as outdated.

Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@EgorBo
Copy link
Member Author

EgorBo commented May 28, 2025

@EgorBot -amd -arm

using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    private static Dictionary<string, int> Dictionary =
        new()
        {
            { "1", 1 },
            { "222", 2 },
            { "3333", 3 },
            { "44444", 4 },
        };

    [Benchmark]
    [Arguments("44444")]
    public int Lookup(string key) => Dictionary[key];
}

@EgorBo
Copy link
Member Author

EgorBo commented May 28, 2025

PTAL @AndyAyersMS @dotnet/jit-contrib

@AndyAyersMS I remember you recently made a fix for a similar case, but in your case it was not the root inlinee.
This fix is purely for BDN-like cases where simple methods become roots

E.g. the benchmark ^ is significantly improved as FindValue is now inlined while previously we used to give up on it due to large IL size for non-profiled (sufficient/trustful) blocks.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

I thought about doing something lilke this but wondered if it might be a bit too benchmarkish. I had been thinking of modifying the "wrapper method" heuristic but your approach seems simpler and more general, since trust/sufficiency plays out more broadly.

It seems quite possible there is user code written this way where for whatever reason the trivial root method can't be inlined.

This will show an enormous amount of benchmark wins on Windows/Viper when the inlinee is fairly trivial (100's of benchmarks) due to elimination of CET overhead.

@EgorBo EgorBo merged commit ffcd1c5 into dotnet:main May 28, 2025
107 of 109 checks passed
@EgorBo EgorBo deleted the syn-profile-single-edge branch May 28, 2025 16:16
@EgorBo
Copy link
Member Author

EgorBo commented Jun 3, 2025

Improvements:

Regressions:

@LoopedBard3
Copy link
Member

Additional regression from #116270 (the regex regression).

Run Information

Name Value
Architecture x64
OS ubuntu 22.04
Queue TigerUbuntu
Baseline 2a47838c6d353b783ca8466e40d7db756f2d2acf
Compare ffcd1c5442a0c6e5317efa46d6ce381003397476
Diff Diff
Configs CompilationMode:tiered, RunKind:micro

Regressions in System.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock

Benchmark Baseline Test Test/Base Test Quality Edge Detector Baseline IR Compare IR IR Ratio
2.06 ms 2.50 ms 1.21 0.54 False

graph
Test Report

Repro

General Docs link: https://github.com/dotnet/performance/blob/main/docs/benchmarking-workflow-dotnet-runtime.md

git clone https://github.com/dotnet/performance.git
python3 .\performance\scripts\benchmarks_ci.py -f net8.0 --filter 'System.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock*'

System.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock.Count(Pattern: "\w+\s+Holmes\s+\w+", Options: NonBacktracking)

ETL Files

Histogram

JIT Disasms

Docs

Profiling workflow for dotnet/runtime repository
Benchmarking workflow for dotnet/runtime repository

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants