-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Use Type.EmptyTypes and Array.Empty<T>() #9042
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
Conversation
2b5d726 to
4bca7ef
Compare
4bca7ef to
677366a
Compare
|
Can you verify that IIRC, the private code was necessary to keep Windows PowerShell running with supported versions of the desktop CLR, but I measured anyway because I was curious. |
@lzybkr I believe that make sense only after we move to .Net Core 3.0 - the new runtime has huge performance improvements. Although now I could do a simple test using BenchmarkDotNet. |
|
It seems performance of both comparable with .Net Core 3.0 Preview2 taking in account measure errors. BenchmarkDotNet=v0.11.4, OS=Windows 10.0.17763.253 (1809/October2018Update/Redstone5)
Intel Core i5-2410M CPU 2.30GHz (Sandy Bridge), 1 CPU, 4 logical and 2 physical cores
.NET Core SDK=3.0.100-preview-010184
[Host] : .NET Core 3.0.0-preview-27324-5 (CoreCLR 4.6.27322.0, CoreFX 4.7.19.7311), 64bit RyuJIT
TC Disabled : .NET Core 3.0.0-preview-27324-5 (CoreCLR 4.6.27322.0, CoreFX 4.7.19.7311), 64bit RyuJIT
TC Enabled : .NET Core 3.0.0-preview-27324-5 (CoreCLR 4.6.27322.0, CoreFX 4.7.19.7311), 64bit RyuJIT
Runtime=Core Toolchain=.NET Core 3.0
|
|
@iSazonov - did your benchmark use types defined in System.Management.Automation? I seem to recall that was where I saw a difference. |
|
The test code is: [Benchmark(Baseline = true)]
public string[] CoreFXEmptyArray()
{
return Array.Empty<string>();
}
[Benchmark]
public string[] CustomEmptyArray()
{
return EmptyArray<string>();
} |
|
String and object - these are most common. |
|
Do try types in other assemblies. The code is minimal, and if there is a performance difference, I see no reason for the change. |
|
Today I can not compile SMA with .Net Core 3.0 and get types from it.
What runtime you measure with? I guess .Net FrameWork? .Net Core 3.0 has a lot of new optimizations. I saw that 3.0 more faster 2.1 while working on Simple Case Folding. In my measure 3.0 generate identical code for both if TC=0 and different code if TC=1 - the second is so fast that error > value (I could get better result). Disasm file attached System.Text.CaseFolding.IntroBenchmarkBaseline-asm.raw.html.zip |
|
I most likely measured it with 4.6.2. I don't know how important SMA is, you could try using a type defined in you benchmark assembly to see if that is different than |
BenchmarkDotNet=v0.11.4, OS=Windows 10.0.17763.253 (1809/October2018Update/Redstone5)
Intel Core i5-2410M CPU 2.30GHz (Sandy Bridge), 1 CPU, 4 logical and 2 physical cores
.NET Core SDK=3.0.100-preview-010184
[Host] : .NET Core 3.0.0-preview-27324-5 (CoreCLR 4.6.27322.0, CoreFX 4.7.19.7311), 64bit RyuJIT
TC Disabled : .NET Core 3.0.0-preview-27324-5 (CoreCLR 4.6.27322.0, CoreFX 4.7.19.7311), 64bit RyuJIT
TC Enabled : .NET Core 3.0.0-preview-27324-5 (CoreCLR 4.6.27322.0, CoreFX 4.7.19.7311), 64bit RyuJIT
Runtime=Core Toolchain=.NET Core 3.0
The same results. For TC=0 we have reliable results and approximately equal values within the error. For TC=1 error exceeds the value - all is very fast.
This suggests that this measures should be repeated for .Net Core (for each version with which we release?). |
|
Thanks for testing - I don't have any concerns with the change. |
daxian-dbw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @iSazonov for making these changes!
PR Summary
PR Context
The APIs was missing in .Net Core 1.0/1.1 and is now in .Net Core 2.0/2.1 and we can remove our temporary code.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.[feature]to your commit messages if the change is significant or affects feature tests