-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[NativeAOT] Accessing static variables, ideally, should not call runtime helpers. #79436
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsIt is a bit surprising that in a completely static scenario on a completely statically compiled runtime code calls helpers like I am porting some c++ code and see impact on performance from this in a few tight spots. Repro: using System.Runtime.CompilerServices;
internal class Program
{
static int something1;
static string something2;
private static void Main(string[] args)
{
Test();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Test()
{
something1 = 1234;
something2 = "qwer";
Console.WriteLine(something1 + something2);
System.Diagnostics.Debugger.Break();
}
} After compiling for nativeAOT/release, I see in debugger:
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsIt is a bit surprising that in a completely static scenario on a completely statically compiled runtime code calls helpers like I am porting some c++ code and see impact on performance from this in a few tight spots. Repro: using System.Runtime.CompilerServices;
internal class Program
{
static int something1;
static string something2;
private static void Main(string[] args)
{
Test();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Test()
{
something1 = 1234;
something2 = "qwer";
Console.WriteLine(something1 + something2);
System.Diagnostics.Debugger.Break();
}
} After compiling for nativeAOT/release, I see in debugger:
|
Perhaps there are reasons for dynamic indirection, but it feels like - if compiler knows what helpers to call and compiler has generated those helpers, maybe it could just inline the results instead? |
No reason - just a current codegen limitation - we cannot express the access pattern though JitInterface. This is one of the sub-bullets in #64242. Cc @EgorBo this is in your area of interests. |
Closing as completed. Current codegen for ; Method Program:Test()
G_M24707_IG01: ;; offset=0000H
56 push rsi
4883EC20 sub rsp, 32
G_M24707_IG02: ;; offset=0005H
C705FCFFFFFFD2040000 mov dword ptr [(reloc 0x4000000000423508)], 0x4D2 ; static handle
488B3500000000 mov rsi, qword ptr [(reloc 0x4000000000423518)]
488D0D00000000 lea rcx, gword ptr [(reloc 0x4000000000423580)]
48894E08 mov gword ptr [rsi+08H], rcx
8B0D00000000 mov ecx, dword ptr [(reloc 0x4000000000423508)]
E800000000 call System.Number:Int32ToDecStr(int):System.String
488BC8 mov rcx, rax
488B5608 mov rdx, gword ptr [rsi+08H]
E800000000 call System.String:Concat(System.String,System.String):System.String
488BC8 mov rcx, rax
E800000000 call System.Console:WriteLine(System.String)
E800000000 call System.Diagnostics.Debugger:Break()
90 nop
G_M24707_IG03: ;; offset=0046H
4883C420 add rsp, 32
5E pop rsi
C3 ret
; Total bytes of code: 76 |
It is a bit surprising that in a completely static scenario, statically compiled code calls helpers like
__GetGCStaticBase
/__GetNonGCStaticBase
.I am porting some c++ code to c#/NativeAOT and I see impact on performance from this in a few tight spots.
Can the emit for statics be closer to the native compilers?
Repro:
After compiling for nativeAOT/release, I see in debugger:
The text was updated successfully, but these errors were encountered: