JIT should hoist interface method resolution out of loops
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Description
The JIT seems to not host interface method resolution out of loops, it should be possible for it to do that while preserving side effects NREs.
Example code:
```cs
public static class Test
{
public static void A(object o)
{
for (int i = 0; i < 1000; i++)
B(o.ToString());
}
public static void A(IInterface o)
{
for (int i = 0; i < 1000; i++)
B(o.Get());
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void B(string s) {}
public interface IInterface
{
string Get();
}
}
```
Both `ToString` and `Get` resolution should be hoisted out of loop.
### Configuration
Main on Godbolt
### Regression?
No
### Data
https://compiler-explorer.com/z/1KbzTa5M9
Contributor guide
Research direction
Start with the C# reproducer and the linked Compiler Explorer configuration on Godbolt, comparing the generated code for the object.ToString and interface Get loops. Trace the JIT's interface method resolution and its handling of side effects and null-reference exceptions. Done means both resolutions are hoisted out of the loops without changing those observable behaviors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100