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

Minor Type.IsPrimitive improvement #42891

Merged
merged 1 commit into from
Sep 30, 2020
Merged

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Sep 30, 2020

Re-use branch-free version in RuntimeHelpers instead.
It makes Type.IsPrimitive property a bit faster and removes duplicated code:

[Benchmark]
[Arguments(typeof(string))]
[Arguments(typeof(Program))]
[Arguments(typeof(sbyte))]
[Arguments(typeof(int))]
[Arguments(typeof(UIntPtr))]
public bool IsPrimitive(Type type) => type.IsPrimitive;
Before:
|      Method |    type |     Mean |     Error |    StdDev |
|------------ |-------- |---------:|----------:|----------:|
| IsPrimitive | Program | 2.022 ns | 0.0047 ns | 0.0042 ns |
| IsPrimitive |   Int32 | 2.396 ns | 0.0038 ns | 0.0032 ns |
| IsPrimitive |   SByte | 2.406 ns | 0.0053 ns | 0.0047 ns |
| IsPrimitive |  String | 1.986 ns | 0.0007 ns | 0.0006 ns |
| IsPrimitive | UIntPtr | 2.192 ns | 0.0015 ns | 0.0012 ns |

After:
|      Method |    type |     Mean |     Error |    StdDev |
|------------ |-------- |---------:|----------:|----------:|
| IsPrimitive | Program | 1.714 ns | 0.0062 ns | 0.0051 ns |
| IsPrimitive |   Int32 | 1.927 ns | 0.0047 ns | 0.0041 ns |
| IsPrimitive |   SByte | 1.947 ns | 0.0060 ns | 0.0053 ns |
| IsPrimitive |  String | 1.737 ns | 0.0186 ns | 0.0174 ns |
| IsPrimitive | UIntPtr | 1.923 ns | 0.0023 ns | 0.0020 ns |

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 30, 2020
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas jkotas merged commit 8ffc0b3 into dotnet:master Sep 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
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.

3 participants