This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
Make Activator.CreateInstance<T>
50% faster
#8000
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The existing implementation was a bit awkward because of how the intrinsic was implemented in .NET Native (the intrinsic in .NET Native did allocate+call default constructor - in CoreRT we have a separate intrinsic for "get default constructor").
.NET Native required an awkward dance around "uh-oh, this type doesn't have a default constructor, what should I call now". None of that is needed in CoreRT, but we had it there so that we don't diverge too much. It was 3x faster than CoreCLR anyway. We no longer have to worry about diverging and it seems like CoreCLR might be getting a perf boost here for .NET 5, so let's not stay behind.
In this commit:
s_createInstanceMissingDefaultConstructor
flag - we can do this check quickly by comparing the retrieved default constructor withDefaultConstructorOf<ClassWithMissingConstructor>
.AllocatorOf<T>
. This is a new intrinsic that expands to the existingAllocatorOf
dictionary entry that represents the optimized allocator method for T. This entry is normally only used in universal shared code, but it's valid to use it outside of that.AllocatorOf
is doubly-indirect for USG reasons. We should probably keep that for universal shared code anyway.There's still room left for improvement - RyuJIT currently doesn't have support for the
RawCalli
intrinsic and generates a normal calli for them. Normal calli needs to check for fat function pointers. These pointers are never fat pointers.