The result of RuntimeInformation.IsOSPlatform does not change during the application run lifecycle. It would be a nice optimization if JIT intrinsically generate a better code for this method.
For example, for the following method:
private static bool CheckIfOSIsWindows() =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
JIT produces this asm (with VS2019 and .NET Core 3.1 in Release configuration):
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
00007FF810DC0FB2 sub esp,30h
00007FF810DC0FB5 lea rbp,[rsp+30h]
00007FF810DC0FBA xor eax,eax
00007FF810DC0FBC mov qword ptr [rbp-8],rax
00007FF810DC0FC0 call 00007FF810DC0670
00007FF810DC0FC5 mov qword ptr [rbp-8],rax
00007FF810DC0FC9 mov rcx,qword ptr [rbp-8]
00007FF810DC0FCD call 00007FF810DC0778
00007FF810DC0FD2 nop
00007FF810DC0FD3 lea rsp,[rbp]
00007FF810DC0FD7 pop rbp
00007FF810DC0FD8 ret
Instead, it could just produce:
on Windows, and on Unix:
The result of
RuntimeInformation.IsOSPlatformdoes not change during the application run lifecycle. It would be a nice optimization if JIT intrinsically generate a better code for this method.For example, for the following method:
JIT produces this asm (with VS2019 and .NET Core 3.1 in Release configuration):
Instead, it could just produce:
on Windows, and on Unix: