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

Remove unnecessary calls to GetTypeInfo #27974

Merged
merged 1 commit into from
Nov 25, 2020

Conversation

eerhardt
Copy link
Member

GetTypeInfo() calls are no longer necessary just to use Reflection APIs. And typically they allocate a small TypeDelegator object when used, so they should be avoided when not necessary.

I removed the obvious cases from the product, and a few occurrences in test code. However, I didn't tackle every place test code was calling it as there is a diminishing return.

Similar work is done in dotnet/runtime:

{
if (!constructor.IsStatic && constructor.IsPublic)
if (!constructor.IsStatic)
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Hmmmm when?

Copy link
Member

Choose a reason for hiding this comment

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

Is constructor.IsPublic implied? Or does this change ActivatorUtilities.CreateInstance to use non-public ctors? If it's the latter, this seems like a fairly major breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

Previous conversation about this: https://github.com/dotnet/runtime/pull/40227/files#r463897549
TLDR: GetConstructors returns only public constructors

Copy link
Member Author

Choose a reason for hiding this comment

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

Just looked again, it also only returns Instance constructors, so we could remove the IsStatic check from both copies (runtime and aspnetcore) of this code.

https://github.com/dotnet/runtime/blob/1821d9c14b970d58e0768256de138b6c0287e07d/src/libraries/System.Private.CoreLib/src/System/Type.cs#L175-L178

@Pilchie Pilchie added area-blazor Includes: Blazor, Razor Components area-dataprotection Includes: DataProtection area-hosting area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Nov 19, 2020
@Pilchie
Copy link
Member

Pilchie commented Nov 19, 2020

Throwing a bunch of areas on for people to take a look.

@Tratcher
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@halter73 halter73 merged commit d7187b0 into dotnet:master Nov 25, 2020
@eerhardt eerhardt deleted the RemoveGetTypeInfo branch November 30, 2020 16:29
dougbu pushed a commit to dougbu/razor-compiler that referenced this pull request Nov 17, 2021
@amcasey amcasey added area-hosting Includes Hosting area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components area-dataprotection Includes: DataProtection area-hosting Includes Hosting area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants