Skip to content

Trust single-edge synthetic profile #116054

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

Merged
merged 2 commits into from
May 28, 2025
Merged

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

2 participants