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

Fix rounding error in getLikelyClassesOrMethods #86965

Merged
merged 6 commits into from Jun 1, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented May 31, 2023

It seems that sometimes getLikelyClasses reports that fallback has e.g. 1% likelihood where in fact it's 0. It happens because of the rounding error accumulated in getLikelyClassesOrMethods. It prevents JIT from moving that fallback to a cold section.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 31, 2023
@ghost ghost assigned EgorBo May 31, 2023
@ghost
Copy link

ghost commented May 31, 2023

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

Issue Details

It seems that sometimes getLikelyClasses reports that fallback has e.g. 1% likelihood where in fact it's 0. It happens because of the rounding error accumulated in getLikelyClassesOrMethods. It prevents JIT from moving that fallback to a cold section.

public static void Main(string[] args)
{
    for (int i = 0; i < 200; i++)
    {
        Test(new MyClass1());
        Test(new MyClass1());
        Test(new MyClass1());
        Test(new MyClass2());
        Test(new MyClass3());
        Thread.Sleep(16);
    }
}

[MethodImpl(MethodImplOptions.NoInlining)]
static int Test(IValue value) => value.GetValue();
- 1) 00007FFF3995A8C0 (MyClass1) [likelihood:50%]
+ 1) 00007FFF3995A8C0 (MyClass1) [likelihood:51%]
  2) 00007FFF3995AA88 (MyClass2) [likelihood:37%]
  3) 00007FFF3995AC50 (MyClass3) [likelihood:12%]
Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo EgorBo requested a review from AndyAyersMS May 31, 2023 18:59
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.

LGTM

@EgorBo EgorBo merged commit d45a905 into dotnet:main Jun 1, 2023
127 checks passed
@EgorBo EgorBo deleted the fix-rounding-error-pgo branch June 1, 2023 09:57
@dotnet dotnet locked as resolved and limited conversation to collaborators Jul 1, 2023
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.

None yet

2 participants